3 ms·
Interesting. I would have thought that the server would have sent a reset when it received a SYN on a CLOSE_WAIT socket, not ignored it.
by mcguire 10y ago
Interesting. I would have thought that the server would have sent a reset when it received a SYN on a CLOSE_WAIT socket, not ignored it.
- JoeAltmaier 10y agoThe OP describes a local-host scenario, which is a special case and could be cleaned up better, as you describe. The CLOSE_WAIT cannot simply be ignored in the general case. The other side could potentially be still out there, lagging badly. Its important to make a really diligent attempt to close, else other more horrible bugs may happen (two endpoints talking to your same port). I'd suggest the stack should never reallocate a port that is not 'clean'. The root of all this confusion is the small port number space (16 bits). Reusing them in a lossy environment (or buggy client environment) can result in all your sockets being in a bad state in a few seconds. Especially with random allocation - its the 'how many people in the room before two have the same birthday' puzzle - the answer is 'not many' before a collision (reallocation of dirty port) is likely. A solution would be to enlarge the port space - e.g. use uuids that don't ever repeat.
- wyldfire 10y ago> The root of all this confusion is the small port number space (16 bits). IMO the leak is the real bug and the protocols work as intended. Keep in mind that the stack(s) distinguish TCP connections not by merely one 16-bit port number but by (local port, local addr, remote addr, remote port). This quadruple is effectively 96 bits of identification. Enlarging the port space has an astonishingly high cost. IMO, it would be easier to just define a new transport protocol or use a network protocol with more addresses (IPv6, e.g.).
- JoeAltmaier 10y agoIt may distinguish them (filter them for correctness) but port numbers must be unique across all legal tuples, right? So its still a 16-bit space. And the cost of adding 112 bits to each message is perhaps overstated in this modern world. Messages often dwarf that. Though agreed it would help to use a new protocol - once you have a uuid in the message header, you can design a protocol that omits all the other constant fields (ip etc) because the uuid can be associated at every stage with all that.
- wyldfire 10y ago> It may distinguish them (filter them for correctness) but port numbers must be unique across all legal tuples, right? No. TCP connections are distinct from one another only by the entire quadruple. There's no (or very nearly no) invalid combinations of ports and IPs.
- JoeAltmaier 10y agoYes. First, the tuple has 5 elements (including Protocol). True that a router can identify uniquely a connection by this tuple, that doesn't speak to dispatching on the client or server endpoint. Every server will listen on a port with a protocol. But then when a connection is made, it will migrate it to a unique local port. Some sharing is possible. Port 80 can be used for HTTP and UDP simultaneously for instance.
- toast0 10y agoYou could easily run into the same scenario over a real network as well. Perhaps in that case, Linux would send a RST to the SYN; it's hard to know without testing since localhost on linux skips most of the TCP stack, FreeBSD runs the full stack though -- you can get congestion collapse on lo0 if you push it hard enough or find exciting (fixed) bugs in syncookies leading to desynchronized TCP states. 127.0.0.0/8 is a pretty huge selection of ips to talk to yourself with -- if that's not enough ports for you, you can use UNIX sockets or take over DoD address space. (or ipv6)