Skip to content

Require explicit socket port reuse#8940

Merged
dhalbert merged 1 commit into
adafruit:mainfrom
tannewt:esp_accept_listen
Feb 17, 2024
Merged

Require explicit socket port reuse#8940
dhalbert merged 1 commit into
adafruit:mainfrom
tannewt:esp_accept_listen

Conversation

@tannewt

@tannewt tannewt commented Feb 16, 2024

Copy link
Copy Markdown
Member

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

bill88t commented Feb 17, 2024

Copy link
Copy Markdown
>>> 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)

@dhalbert dhalbert left a comment

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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