News for hackers. Stuff that matters.
Re:TCP is UNreliable by tptacek on Friday August 16, 2013 @11:02AM (#6224381)
I voted this up (tried to submit, actually), but is this article correct, or is something in this person's stack not actually programming sockets correctly?

When you call shutdown() to arrange a FIN for a socket, especially after you've sent data and received no application-layer acknowledgement, you're supposed to verify that the connection closed properly. You do this by select()ing on the socket and then read()ing 0 bytes.

The error condition (the RST segment they're getting) is signaled by the "Connection closed by peer" errno --- and -1 from read().

The reliability signals this app needs are built into both TCP and the socket programming interface, from what I can tell. The application-layer acknowledgement it wants appears duplicative.

Re:TCP is UNreliable by oesmith on Friday August 16, 2013 @11:45AM (#6224693)
> The reliability signals this app needs are built into both TCP and the socket programming interface, from what I can tell. The application-layer acknowledgement it wants appears duplicative.

An ACK only suggests that a segment has reached the recieve buffer successfully. If the receiving application crashes between buffering incoming data and successfully processing it, that's expressly not TCP's problem. The RST will signal that the receiver has died, but does not imply whether or not the application has successfully processed any buffered data up to that point.

AFAIK, an application-layer acknowledgement is the only way to solve this problem.

Re:TCP is UNreliable by tptacek on Friday August 16, 2013 @12:14PM (#6224923)
I agree that there are circumstances where you need application-layer acks, SMTP being a canonical example.

However, there are other cases where you don't need lock-step app-layer acknowledgements; for instance, if your messages are idempotent.

I'm really just reacting to the forensic work in this article, which suggests (maybe I'm misreading) a problem that TCP doesn't actually have.

Re:TCP is UNreliable by oesmith on Friday August 16, 2013 @01:25PM (#6225415)
Yes, if all you want is to confirm that a TCP connection has closed and flushed correctly, then AFAIK, that's entirely possible with a [shutdown, select, read] sequence.

I struggle to understand why an RPC system (as detailed in the article) wouldn't want an app-level acknowledgement though...

Re:TCP is UNreliable by abofh on Friday August 16, 2013 @11:28AM (#6224568)
Without looking at the code, it's hard to say, typically errors like the one described won't be caught by return values of read/write, but by return values of close() -- which many many people don't bother to check. (Not saying that's what happened, but that's my bet)
Re:TCP is UNreliable by tptacek on Friday August 16, 2013 @11:33AM (#6224622)
Did they close() the socket? If you write data to a socket, and receive no signal that it's been processed, shouldn't you shutdown(2), select(2), then read(2) before you close(2) it?
Re:TCP is UNreliable by BetaCygni on Friday August 16, 2013 @11:33AM (#6224614)
> after you've sent data and received no application-layer acknowledgement

This would be the most robust fix. Have the server return "OK" or something after it has processed the data. It could have silently crashed but still accept connections.

Re:TCP is UNreliable by tptacek on Friday August 16, 2013 @11:35AM (#6224633)
I'm not sure I see how this is more robust than simply checking to make sure you had an orderly close. The orderly close check should also catch the case where the application crashes after its TCP stack has received the data but before the application processed it.

I'm not saying there's never any point to application acknowledgements; look at any careful SMTP server implementation for a study of how to handle these problems. TCP can promise a reliable transport but obviously not a reliable disk.

Re:TCP is UNreliable by noselasd on Friday August 16, 2013 @12:01PM (#6224822)
Though, the contract you have with TCP , is between TCP at your end and the TCP at the peer, not that it also have delivered the data to the application of the peer.

If the peer crashes just as it read() the data, but didn't process it, it will look just as a normal clean close on the sender machine if there arn't more data laying around in the TCP buffers.

Re:TCP is UNreliable by tptacek on Friday August 16, 2013 @12:12PM (#6224909)
To be clear, you're talking about the case where the application dequeues the data from its receive queue and then crashes. If you close a socket without reading queued data, you get an RST.