-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Socket closing if timed out and no data on socket #3836
Comments
@hierophect please chat with @tannewt and @brentru, im not the one using the code :) |
@hierophect @brentru You can't just remove the socket close because it is valid sometimes. I think what's missing is a test against the timeout condition. If the while loop has timed out, then we don't want to close the socket. |
I've followed up with recommendations on #3854 |
@tannewt can you double check if you submitted your review? I don't see anything on my PR. |
Yup! They were pending. Sorry about that. You should see them now. Thanks for the ping. |
@tannewt I wanted to follow up with you on this issue to talk more about the socket close behavior. Under what conditions do you want sockets to close automatically (ie, what's the scenario where they could leak when using |
We should call our internal close when the internal APIs indicate that the socket has been closed (by the other end or the lower layers.) |
@brentru can you double check that this is fixed? |
@hierophect Ok - I'll verify with MiniMQTT. Which CircuitPython version should I test on? |
@brentru latest. This should be all wrapped up with the new SSLSocket. |
@hierophect this is fixed with the new SSLSocket Tested with |
Sounds good, thanks for testing. |
If no data is received on a socket, and the socket has timed out, a socket will close. Subsequent reads raise
OSError: [Errno 9] EBADF
.I dug deeper, this behavior is expected (https://github.com/adafruit/circuitpython/blob/main/ports/esp32s2/common-hal/socketpool/Socket.c#L123) on the esp32-s2.
However, closing the socket immediately makes it difficult to poll a socket to check if data is available.
For example, polling a socket for a response, like in MiniMQTT (https://github.com/brentru/Adafruit_CircuitPython_MiniMQTT/blob/cpython-s2/adafruit_minimqtt/adafruit_minimqtt.py#L872), raises OSError instead of simply timing out and leaving the socket open.
Could we instead raise a timeout or perform some other behavior? CPython raises a
socket.timeout
(https://docs.python.org/3.8/library/socket.html#socket.timeout) error for this operation and leaves the socket open.Code example, , receiving one byte of code at a time from a server, until it reads
0
:Then I set up a simple tcp packet server using netcat (
nc -l 23999
)Output:
The text was updated successfully, but these errors were encountered: