Skip to content

Fix DHCP socket leak #122

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

Merged
merged 6 commits into from
Jul 21, 2023
Merged

Fix DHCP socket leak #122

merged 6 commits into from
Jul 21, 2023

Conversation

BiffoBear
Copy link
Contributor

Closes #121. Moved all references to hardware sockets in the DHCP module to _handle_dhcp_message and _receive_dhcp_response. Added try… finally block to ensure that the hardware socket is always closed.
Made the socket number a local method attribute since it doesn't need to be stored.
Removed unused methods to initialise and release hardware sockets.
Refactored DHCP module to use higher level calls to the WIZNET5K instance.
Renamed several methods in WIZNET5K as they are private and no longer called from outside WIZNET5K.
Added _read_socket_reservations and _read_sndport methods to WIZNET5K to help dumping of socket state for troubleshooting.
Tested with a DHCP server and without a DHCP server to force a TimeoutError. Hardware socket closed in both cases.
Tests carried out with wiznet5k_simpletest.py on w5100s, w5500 and w6100 chips.

Copy link
Contributor

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks for the fixes @BiffoBear!

I tested successfully with simpletest, simpleserver, and cheerlight examples with an Ethernet Featherwing and Feather S3 TFT 8.2.0-beta.0.

I also did a quick check with git grep in the learn guide repo and didn't find any usages of any of the now-private functions.

@FoamyGuy FoamyGuy merged commit b564228 into adafruit:main Jul 21, 2023
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jul 22, 2023
Updating https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k to 5.0.1 from 3.0.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#130 from fasteddy516/fix_socket_swap
  > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#123 from BiffoBear/remove_ntp_client
  > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#122 from BiffoBear/fix_socket_leaks

Updating https://github.com/adafruit/Adafruit_CircuitPython_Requests to 2.0.1 from 2.0.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Requests#136 from DJDevon3/WorkingBranch

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Updated download stats for the libraries
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The DHCP module is not releasing its socket after use.
2 participants