Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TcpListener: drain all pending accepts
This commit makes `TcpListener::accept` try to accept the next connection without waiting for a notify, if the previous connection couldn't be established because the peer already went away. The change is meant to fix a bug where a pending connection sometimes wouldn't be accepted. Consider this series of events: * Server runs `TcpListener::accept`. There are no connections pending, so it starts waiting on the `notify`. * Client 1 sends a SYN, which gets pushed to `ServerSocket::deque` and `ServerSocket::notify` is notified. * Client 2 sends a SYN, which gets pushed to `ServerSocket::deque` and `ServerSocket::notify` is notified. * Client 1 goes away. * Server wakes up because the `notify` was notified. * Server tries to accept the connection from client 1, which fails because client 1 went away. * Server starts waiting on the `notify` again. We end up in a situation where the connection from client 2 is still pending but the server doesn't accept it because it's waiting for a notification that was already sent.
- Loading branch information