Repository navigation
Conversation
The peer is not required to send us `CloseNotify`, but if the socket has shutdown we should act accordingly.
|
I think @hawkw is going to review this. Just want to add that we should add a test for this before merging. |
hawkw
left a comment
There was a problem hiding this comment.
one major comment here --- what do you think?
| /// Are we done? i.e., have we processed all received messages, | ||
| /// and received a close_notify to indicate that no new messages | ||
| /// will arrive? | ||
| /// will arrive or ran out of bytes on the incoming TLS stream? |
There was a problem hiding this comment.
the comments #563 (comment), #563 (comment), #563 (comment) suggest that a TLS connection closing without a CloseNotify ought to be considered an error (although the user should be able to ignore that error if they choose to). it looks like this code will now always return a clean error (Ok(0)) regardless of whether a CloseNotify was received or the TCP connection just closed without one?
I think we should probably be distinguishing between CloseNotify and closing a connection without a CloseNotify, and return an io::Error in that case.
IMO, ErrorKind::UnexpectedEof is probably the most correct error kind to use to indicate that a connection was closed without a CloseNotify, but I'm open to being convinced otherwise...i do think it's important to use an ErrorKind that rustls won't return in other cases, so user code can programmatically distinguish between the underlying connection EOF and other errors.
I wonder if it's also worth adding an option to consider TCP connection EOFs without CloseNotify a clean EOF, since some use cases may require talking to peers that don't support CloseNotify? Or is it sufficient to just allow the user to ignore that error kind themself?
There was a problem hiding this comment.
I agree that this should be reported as an error rather than a 'clean' EOF. UnexpectedEof sounds like an excellent option, as does ConnectionAborted.
There was a problem hiding this comment.
IMO, I have a slight preference for UnexpectedEof over ConnectionAborted, as I think it's possible that the I/O reader passed to read_tls may return ConnectionAborted, but it probably won't return UnexpectedEof, so it's clearer where the error came from. But, either is probably fine here.
|
@ctz I probably won't have much time to work on this over the weekend. If you want to take it over, please feel free. Otherwise I'll pick it back up on Monday. |
|
I think I've addressed the above comments in 0b2b9bf |
|
FWIW, your changes look good to me. |
| /// sized chunks (like a socket or pipe might). | ||
| pub(crate) fn read_tls(&mut self, rd: &mut dyn io::Read) -> io::Result<usize> { | ||
| self.message_deframer.read(rd) | ||
| let res = self.message_deframer.read(rd); |
There was a problem hiding this comment.
Probably the read() should not happen here if self.peer_eof is already true? The peer may not immediately terminate the TCP connection after sending a CloseNotify, and read() here will return WantRead error, leading to the caller waiting in Pending instead of getting a ConnectionAborted error with CloseNotify alert received as the message.
The peer is not required to send us
CloseNotify, but if the socket hasshutdown we should act accordingly.
Fixes #777.
Probably needs further comment updates and some tests.