-
-
Notifications
You must be signed in to change notification settings - Fork 99
Fix race conditions and improve robustness during socket I/O #779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
887399d
to
4f1662e
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #779 +/- ##
==========================================
- Coverage 79.24% 78.99% -0.26%
==========================================
Files 29 29
Lines 4197 4261 +64
Branches 538 549 +11
==========================================
+ Hits 3326 3366 +40
- Misses 727 750 +23
- Partials 144 145 +1 |
4f1662e
to
4833dac
Compare
cheroot/makefile.py
Outdated
|
||
try: | ||
super().close() | ||
except (OSError, SysCallError) as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be in a var?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i can reuse acceptable_sock_shutdown_error_codes?
cheroot/test/test_conn.py
Outdated
assert faux_get_map.conn_closed | ||
|
||
|
||
class TestBufferedWriter: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop the class. This should go into test_makefile.py
.
@@ -0,0 +1,2 @@ | |||
Fixed race conditions to make socket I/O more resilient during connection teardown. | |||
-- by :user:`julianz-` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-- by :user:`julianz-` | |
-- by :user:`julianz-` |
cheroot/server.py
Outdated
else: | ||
self.conn.wfile.write(chunk) | ||
except (SysCallError, ConnectionError, OSError) as e: | ||
error_code = e.errno if isinstance(e, OSError) else e.args[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a number of places where this is repeated. It's worth having a helper function, I think.
048d898
to
f0471ca
Compare
d23845a
to
1c7c0c0
Compare
Fixes to make socket I/O more resilient during connection teardown. 1. BufferedWriter's write(): Added error handling to ignore common socket errors (e.g., ECONNRESET, EPIPE, ENOTCONN, EBADF) that occur when the underlying connection has been unexpectedly closed by the client or OS. This prevents a crash when attempting to write to a defunct socket. 2. BufferedWriters's close(): Made idempotent, allowing safe repeated calls without raising exceptions. 3. Needed to add explicit handling of WINDOWS environments as these are seen to throw Windows specific WSAENOTSOCK errors. Includes new unit tests to cover the idempotency and graceful handling of already closed underlying buffers.
1c7c0c0
to
210d2a9
Compare
Fixed race conditions to make socket I/O more resilient during connection teardown.
write()
: Added error handling to ignore common socket errors (e.g.,ECONNRESET
,EPIPE
,ENOTCONN
,EBADF
) that occur when the underlying connection has been unexpectedly closed by the client or OS. This prevents a crash when attempting to write to a defunct socket.close()
: Made idempotent, allowing safe repeated calls without raising exceptions.WSAENOTSOCK
errors.Includes new unit tests to cover the idempotency and graceful handling of already closed underlying buffers.
This change is