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

Wss_server example no longer accepts new connections after several reconnects (IDFGH-7609) #9163

Closed
EN20M opened this issue Jun 15, 2022 · 3 comments
Assignees
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@EN20M
Copy link

EN20M commented Jun 15, 2022

Environment

  • Development Kit: none
  • Module or chip used: ESP32-WROOM-32E
  • IDF version: v4.4.1
  • Build System: idf.py
  • Compiler version: xtensa-esp32-elf-gcc (crosstool-NG esp-2021r2-patch3) 8.4.0
  • Operating System: Windows
  • (Windows only) environment type: Plain Command Prompt
  • Using an IDE?: No
  • Power Supply: external 3.3V

Problem Description

When running the wss_server example after connecting a client, disconnecting and reconnecting it ~10 times the next reconnect fails. It seams as if every connection uses a new socket and once the default max_clients are reached no new connections are possible.

Expected Behavior

  1. The sockets' storage would be marked as unused after it got closed/disconnected so it can be reused.
  2. Since lru_purge_enable is true in the example I thought the least recently used socket would be reused anyway.

Actual Behavior

W (129257) httpd: httpd_accept_conn: error in accept (23)

indicates that all possible storage for 10 simultanious clients is used up even though no client is connected and only one tryes to connect

Steps to reproduce

  1. Run the wss_server example
  2. connect a client
  3. disconnet the client
  4. reconnect the client
  5. repet 3. and 4. untill the reconnect fails (around 10 connects in total)

I attatched an html file that I run in my browser to connect to the wss_server in the broser you can type in the IP the esp gets from your router.

Code to reproduce this issue

wss_server example

Debug Logs

...
I (115957) wss_echo_server: New client connected 62
I (115967) wss_echo_server: Handshake done, the new connection was opened
I (118987) wss_echo_server: frame len is 0
I (118997) wss_echo_server: Client disconnected 62
I (123417) wss_echo_server: New client connected 63
I (123437) wss_echo_server: Handshake done, the new connection was opened
I (125647) wss_echo_server: Active client (fd=63) -> sending async message
I (125787) wss_echo_server: frame len is 0
I (125787) wss_echo_server: Client disconnected 63
W (129257) httpd: httpd_accept_conn: error in accept (23)
W (129257) httpd: httpd_server: error accepting new connection

Note: I removed my credentials from the sdkconfig
test_client.zip
sdkconfig.zip

@espressif-bot espressif-bot added the Status: Opened Issue is new label Jun 15, 2022
@github-actions github-actions bot changed the title Wss_server example no longer accepts new connections after several reconnects Wss_server example no longer accepts new connections after several reconnects (IDFGH-7609) Jun 15, 2022
@ESP-YJM
Copy link
Collaborator

ESP-YJM commented Jun 15, 2022

@EN20M Thanks for reporting this bug. I think you can add
close(sockfd);
after https://github.com/espressif/esp-idf/blob/master/examples/protocols/https_server/wss_server/main/wss_server_example.c#L103

@espressif-bot espressif-bot added Status: In Progress Work is in progress and removed Status: Opened Issue is new labels Jun 15, 2022
@EN20M
Copy link
Author

EN20M commented Jun 15, 2022

Thanks for this incredibly fast response.
Works absolutly fine.
I'm more than happy with that solution but shoudn't lru_purge_enable have jumped in or am I misinterpreting how that is supposed to work?

@ESP-YJM
Copy link
Collaborator

ESP-YJM commented Jun 16, 2022

@EN20M I think enable lru_purge_enable which indeed will close the least recently used one. But in userspace, we have defined close callback function and in here https://github.com/espressif/esp-idf/blob/master/components/esp_http_server/src/httpd_sess.c#L359 will call userspace close function wss_close_fd. And you will find no place to close this socket.

@espressif-bot espressif-bot added Resolution: NA Issue resolution is unavailable Status: Done Issue is done internally Resolution: Done Issue is done internally and removed Status: In Progress Work is in progress Resolution: NA Issue resolution is unavailable labels Jun 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally
Projects
None yet
Development

No branches or pull requests

3 participants