-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Ensure orderly shutdown of ssl socket #7291
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
Conversation
A crash would occur if an SSL socket was not shut down before `gc_deinit()`. I do not fully understand the root cause, but some object deinitialization / deallocation prior to `gc_deinit` leaves the SSL object in an inconsistent state. Rather than resolve the root cause, instead ensure that the closing of the user socket also closes the SSL socket. Closes: adafruit#6502
I am going to spend a little time seeing if I can find the root cause. |
I do not understand the flow all that well, but this seems a bit fishy to me: circuitpython/ports/espressif/common-hal/socketpool/Socket.c Lines 609 to 616 in 9e104c0
Under what circumstances is the passed in socket not a Socket object? Could it be an SSLSocket ? If so then fields in it are set willy-nilly. Also the SSLSocket would not be shut down. And if it's a plain Socket , it's kind of being rendered unfunctional, but the underlying lwip socket isn't decommissioned in any way.
|
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 like the basic idea of this: it is more robust than the previous code.
One q on a specific change, and also a question in the main comments thread.
I had a theory that for an ssl socket |
The program I tried:
|
Scott answered this in a voice chat. The routine is actually initializing a socket object for use by the web workflow. The name is not very self-documenting, so changing it and adding appropriate comments would be welcome as a separate PR. |
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.
👍
A crash would occur if an SSL socket was not shut down before
gc_deinit()
.I do not fully understand the root cause, but some object deinitialization / deallocation prior to
gc_deinit
leaves the SSL object in an inconsistent state.Rather than resolve the root cause, instead ensure that the closing of the user socket also closes the SSL socket.
Testing performed: on Feather ESP32S3 TFT run the reproducer script >10 times. Before, it crashed after 1 time. However, running 10 times helps show I'm not using up socket file descriptors accidentally.
This feels a bit voodoo so I'd love it if instead of incorporating this blindly, someone else went deeper and found the truth.
Closes: #6502