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

HTTP listen socket not closed in httpd_stop() leading to bind error 112 (EADDRINUSE) (IDFGH-1060) #3381

Closed
henrix opened this issue Apr 28, 2019 · 2 comments

Comments

@henrix
Copy link

henrix commented Apr 28, 2019

Hello,

I've created a web app based on the example http_server.
httpd is started and stopped via an external toggle switch.
If starting and stopping httpd without opening the website in a browser, everything is fine.
However, if I open the website (and close it again) and restart httpd, I get bind error 112 (EADDRINUSE).
It seems that the listen socket is not closed properly if the website was opened once.
SO_REUSEADDR is enabled in sdkconfig.
Is there a way to get the listen socket via httpd API to close it properly or is something else needed?

Thanks!

@github-actions github-actions bot changed the title HTTP listen socket not closed in httpd_stop() leading to bind error 112 (EADDRINUSE) HTTP listen socket not closed in httpd_stop() leading to bind error 112 (EADDRINUSE) (IDFGH-1060) Apr 28, 2019
@anurag-kar
Copy link
Contributor

@henrix SO_REUSEADDR is not set on the listening socket of httpd, so you need to wait about 30 seconds before starting httpd again. Here is a patch which should make this work by calling setsockopt() on the listener socket. In the meanwhile I'll see if this can feature can be added upstream.

httpd_reuseaddr.patch.txt

@henrix
Copy link
Author

henrix commented Apr 29, 2019

@anurag-kar Thanks a lot!

@henrix henrix closed this as completed Apr 29, 2019
igrr pushed a commit that referenced this issue May 6, 2019
…ing server without delay

Issue : Restarting the server without 30sec delay between httpd_stop() and httpd_start() causes EADDRINUSE error
Resolution : Use setsockopt() to enable SO_REUSEADDR on listener socket

Closes #3381
igrr pushed a commit that referenced this issue May 10, 2019
…ing server without delay

Issue : Restarting the server without 30sec delay between httpd_stop() and httpd_start() causes EADDRINUSE error
Resolution : Use setsockopt() to enable SO_REUSEADDR on listener socket

Closes #3381
trombik pushed a commit to trombik/esp-idf that referenced this issue Aug 9, 2019
…ing server without delay

Issue : Restarting the server without 30sec delay between httpd_stop() and httpd_start() causes EADDRINUSE error
Resolution : Use setsockopt() to enable SO_REUSEADDR on listener socket

Closes espressif#3381
wujiangang pushed a commit to espressif/ESP8266_RTOS_SDK that referenced this issue May 6, 2023
…erver without delay

Issue : Restarting the server without 30sec delay between httpd_stop() and httpd_start() causes EADDRINUSE error
Resolution : Use setsockopt() to enable SO_REUSEADDR on listener socket

Closes espressif/esp-idf#3381
wujiangang pushed a commit to espressif/ESP8266_RTOS_SDK that referenced this issue May 6, 2023
…erver without delay

Issue : Restarting the server without 30sec delay between httpd_stop() and httpd_start() causes EADDRINUSE error
Resolution : Use setsockopt() to enable SO_REUSEADDR on listener socket

Closes espressif/esp-idf#3381
loganfin pushed a commit to Lumenaries/esp_http_server that referenced this issue Apr 23, 2024
…ing server without delay

Issue : Restarting the server without 30sec delay between httpd_stop() and httpd_start() causes EADDRINUSE error
Resolution : Use setsockopt() to enable SO_REUSEADDR on listener socket

Closes espressif/esp-idf#3381
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

No branches or pull requests

2 participants