Terms

  • C: client
  • S: server
  • A: active
  • P: passive
  • ssthresh: slow-start threshold
  • FR: fast retransmit
  • FCQ: full connection q

TCP

  • Why we need 3 network calls during init handshake, and 4 to terminate?
    • S needs to ensure that C gets the ACK
    • During the second FIN, the server can not merge it because it needs to send remaining data. The first FIN only ensures that C has no remaining data.
  • What are possible reasons of many TIME_WAIT? Why wait 2 MSL?
    • TIME_WAIT is A side’s (normally client) state after receives FIN from P side (normally server) and replied ACK
    • Client has to wait 2 * MSL so that server’s resend FIN will timeout, 2 * MSL is the time for server to try FIN twice (first time being the normal try). Otherwise, the server’s FIN may go into the next session
    • Normally MSL is between 30s to 2 mins
  • What are possible reasons of many CLOSE_WAIT?
    • A state for P (normally server). When A sends FIN and P doesn’t not receive the ACK, it will remain established. Needed so that client can ACK all on-the-fly but after FIN data. will set K+1 as ACK number.
    • A common problem is not closing the connection from client (while the client side maybe closed due to long idleness)
  • TCP congestion control, how is it done? How does tcp decide there is congestion?
    • TCP tahoe: double frames sent until we reach ssthresh, and after that we just send 1 more than before.
    • To avoid the stampede effect. Once congestion is reached (detected by loss of packet), we will FR and halve the ssthresh.
    • FR receives a later frame, it will just ACK the last one it is expecting
    • Note that different algos, sets different value to the initial window size
  • Suppose A and B established connection with no data sent, and then B restarts, what is the state of conneciotn on A? How to get rid of/move on from this state?
    • A will remain established, and recycled by the OS after timeout
  • Half connection Q vs Full conneciton Q
    • FCQ is for ESTABLISHED state
    • If you have many SYN-RCVD, maybe a sign of SYN flood DDoS. Connection is now to half-opened state inside the half-connection queue
  • When C starts first handshake but S is unable to process, what does S return?
    • S will resend syn+ack in a timed way, forces the client to think the original ACK is lost, so just retry.
  • How does TCP congestion control work?
  • How does fast retry works?
  • Tcp quick resend and congestion control
  • Why tcp may have sticky packt problem, but UDP does not?
    • UDP header has 16 bits to specify datagram’s length, but TCP doesn’t have that
    • That is why netty uses various frame decoders

HTTP

  • keep-alive: reuse the underlying TCP connection between requests. Need a timeout so server can release.
    • Client side may need a shorter timeout cleanup thread. Otherwise, server may send a FIN when the new request comes
  • how to handle cross domain problem?
  • resend vs redirect?