Mehdi Akiki

Posts tagged "tcp"

  • Published on

    Investigation · Part 7 of 10 · Following a TCP connection

    TIME_WAIT: Why a Closed Connection Stays Around

    My client and my server closed 500 connections, and the kernel kept 500 sockets for 60 more seconds. I measured which side keeps TIME_WAIT, why tcp_fin_timeout does not change it, how the client side runs out of local ports, and why a restarted server can fail to bind.
  • Published on

    Investigation · Part 6 of 10 · Following a TCP connection

    What close() Really Sends: FIN, RST and Unread Data

    close() returns 0 and the program learns nothing more. I made five small experiments to see what the other side gets: a clean end of file, a reset, a half-closed connection, a broken pipe that kills a C program, and CLOSE-WAIT sockets that never go away.
  • Published on

    Investigation · Part 5 of 10 · Following a TCP connection

    What a Full Socket Buffer Does to the Sender

    My sender wrote 2.6 MB to a peer that never read anything, and every send() said success. I looked where these bytes waited, what setsockopt really does to the buffer sizes, how a blocking sender is slowed down for free, and how an unbounded queue breaks this.
  • Published on

    Investigation · Part 4 of 10 · Following a TCP connection

    Why recv() Returns Less Than You Asked: TCP Is a Byte Stream

    Three send() calls arrived in one recv(), and one send() of 1 MiB arrived in seventeen. TCP keeps the bytes and their order, not the boundaries between your writes. I broke a small JSON reader with two inputs and fixed it with a length prefix and with lines.
  • Published on

    Investigation · Part 3 of 10 · Following a TCP connection

    Why a Small Write Can Wait 40 Milliseconds: Nagle and Delayed ACK

    My client wrote each request in two small pieces, and almost every request took 43 ms or more on loopback, where a round trip costs microseconds. I followed it with strace, ss and the kernel counters to see how Nagle's algorithm and delayed ACK wait for each other.