Skip to content
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

Require explicit socket port reuse #8940

Merged
merged 1 commit into from
Feb 17, 2024
Merged

Conversation

tannewt
Copy link
Member

@tannewt tannewt commented Feb 16, 2024

Doing it implicitly can lead to mistaken socket leaks and reuse. It now matches CPython.

Fixes #8443

Doing it implicitly can lead to mistaken socket leaks and reuse.
It now matches CPython.

Fixes micropython#8443
@tannewt tannewt added this to the 9.0.0 milestone Feb 16, 2024
@tannewt tannewt requested a review from jepler February 16, 2024 22:34
@bill88t
Copy link

bill88t commented Feb 17, 2024

>>> import wifi
>>> import socketpool
>>> pool = socketpool.SocketPool(wifi.radio)
>>> socket = pool.socket(pool.AF_INET, pool.SOCK_STREAM)
>>> socket.bind(("0.0.0.0", 20))
>>> socket2 = pool.socket(pool.AF_INET, pool.SOCK_STREAM)
>>> socket.bind(("0.0.0.0", 21))
>>> socket2.close()
>>> socket2 = pool.socket(pool.AF_INET, pool.SOCK_STREAM)
>>> socket.bind(("0.0.0.0", 21))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: [Errno 112] EADDRINUSE

So... how are we supposed to remake sockets exactly?
There isn't an .unbind() we can use. socket.setsockopt(pool.SOL_SOCKET, pool.SO_REUSEADDR, 1)

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

I am going to merge this, but will mention in the release notes that this is a breaking change and mention socket.setsockopt(pool.SOL_SOCKET, pool.SO_REUSEADDR, 1)

@anecdata
Copy link
Member

just for completeness of this thread... raspberrypi SO_REUSEADDR implementation added in #9084

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

idf v5.1 listen/accept race condition ends up losing clients
4 participants