Fix possible AttributeError and OSError on calling TCPTransport.close() #438
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull request
Choose Correct
Describe the pull request
This PR fixes two bugs:
socket.shutdown
orsocket.close
to throwOSError
s if the underlying file descriptor is no longer valid. A typical scenario where this could occur is when the remote party of a TCP connection closes the connection and the kernel cleans up the descriptor before the local party can callTCPTransport.close
. This error is now caught, as theclose
effectively did what it intended to do: make sure the socket is closed.TCPTransport.close
may be called multiple times, typically when both sides of a TCP connection try to close at the same time. In this case, both_base_receive
and some user code callclose
in any order, resulting in anAttributeError
, as_sock
would be set toNone
by the first call. This error is now guarded against by locking and checking that_sock
is notNone
yet.To Reproduce
OSError
: close a TCP connection created by aTCPTransport
a bunch of times from the remote node, then callclose
on theTCPTransport
. Not sure how deterministic this is on other systems, but in our system this was almost guaranteed to cause this problem.AttributeError
: simply callclose
multiple times. For a more realistic scenario, have the remote party and the local party attempt to close theTCPTransport
at roughly the same times.Expected behavior
These errors are not propagated to the user.
Desktop (please complete the following information):
debian:bookworm-slim
with eRPC installed.Steps you didn't forgot to do