Repository navigation
Close accepted client sockets on poll() early returns - #113
Merged
Merged
Conversation
Close `conn` before returning `NO_REQUEST` on `EAGAIN`, `ECONNRESET`, `MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE`, and `SSLV3_ALERT_CERTIFICATE_UNKNOWN` in `Server.poll()`, and break when `sock.recv_into(...) == 0` in `_receive_header_bytes()` and `_receive_body_bytes()`. Fixes adafruit#41 Signed-off-by: Sophia Boettcher <sboettcher@ub313.net>
Move the retryable errnos into a module-level tuple so the check doesn't allocate a new tuple on every error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
I refactored the error handling to do the tests all at once to avoid code duplication. I put the errno values in a module-level tuple that is constructed only once (instead of on each check). |
dhalbert
reviewed
Nov 10, 2026
dhalbert
left a comment
Contributor
There was a problem hiding this comment.
Thanks! I refactored the tests to reduce the code size, but did not change the semantics.
dhalbert
approved these changes
Nov 10, 2026
adafruit-adabot
pushed a commit
to adafruit/Adafruit_CircuitPython_Bundle
that referenced
this pull request
Nov 12, 2026
Updating https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer to 4.8.3 from 4.8.2: > Merge pull request adafruit/Adafruit_CircuitPython_HTTPServer#113 from sboettch/fix-poll-socket-leak-41 Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Added the following libraries: Adafruit_CircuitPython_LT8912B
Author
|
Thank you so much for the review and the cleanup.. i learned from the refactor 🌸 warmly, s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #41
Hello Adafruit CircuitPython maintainers, and thank you for maintaining
Adafruit_CircuitPython_HTTPServer. I am a citizen applied data scientist working on WebHealth (an open public-interest security observatory), and while investigating issue#41(Connection refused after some time/multiple requests on Wiznet5k Pico W5100S), I traced an accepted-socket leak on earlyreturn NO_REQUESTpaths inServer.poll()and put together this focused fix.Fixes:
connsocket insideServer.poll()(adafruit_httpserver/server.py, lines481-533) before earlyreturn NO_REQUESTpaths onEAGAIN,ECONNRESET,MBEDTLS_ERR_SSL_FATAL_ALERT_MESSAGE, andSSLV3_ALERT_CERTIFICATE_UNKNOWN(adafruit_httpserver5.0.0on CircuitPython9.2.1) so hardware socket pools (Wiznet5kW5100S/W5500 4-8 socket pools and Pico Wsocketpool) do not leak descriptors across aborted connections.sock.recv_into(...) == 0in_receive_header_bytes()and_receive_body_bytes()(adafruit_httpserver/server.py, lines323-359,RFC 9112Section 9.6) so a client closing its write stream before\r\n\r\nor beforeContent-Lengthbytes does not spinserver.poll()until timeout.Testing:
conn.close()onEAGAIN/ECONNRESET/ TLS-alert early returns and single-read exit onrecv_into(...) == 0half-closed streams across 6 offline unit vectors.Thank you for reviewing, and please let me know if you would like any adjustments to the exception handling or test structure.
Warm regards,
Sophia Boettcher