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

The IDF websocket server does not handle multiple simultaneous connections (at least the example doesn't) (IDFGH-7162) #8596

Closed
pjsg opened this issue Mar 16, 2022 · 12 comments
Labels
Resolution: Done Issue is done internally Status: Done Issue is done internally

Comments

@pjsg
Copy link

pjsg commented Mar 16, 2022

Environment

  • Development Kit: Random ESP32 board
  • Module or chip used: ESP32-DOWDQ6
  • IDF version (run git describe --tags to find it):
    v4.4-beta1-284-gd83021a6e8
  • Build System: idf.py
  • Compiler version (run xtensa-esp32-elf-gcc --version to find it):
    xtensa-esp32-elf-gcc (crosstool-NG esp-2021r2) 8.4.0
  • Operating System: Linux
  • (Windows only) environment type: [MSYS2 mingw32|ESP Command Prompt|Plain Command Prompt|PowerShell].
  • Using an IDE?: No
  • Power Supply: USB

Problem Description

I'm running the IDF4.4 (commit d83021a) and running the unmodified example examples/protocols/http_server/ws_echo_server.

To test it, I'm using websocat (from https://github.com/vi/websocat ) to make a connection to the websocket server and interact with it. In particular, I have this script (called dosend -- and this particular board is at 192.168.1.131)

#!/bin/bash

(echo foo; sleep 1; echo bardsfsdkfsdflskf; sleep 1; echo djfsldkjfskljfslkjfsdlkjfsldkjfklsjfslkf) | websocat ws://192.168.1.131/ws 

This script works fine provided that I only run one copy at a time. If I run four copies at the same time, then I get log messages from the ESP32 like:

W (34089) httpd_ws: httpd_ws_recv_frame: WS frame is not properly masked.
E (34089) ws_echo_server: httpd_ws_recv_frame failed to get frame len with 259

I launch four copies with the command (on my linux laptop)

./dosend & ./dosend & ./dosend & ./dosend &

I originally found this in an application that I was building, but the issue reproduces in the provided echo example.

Other items if possible

Since this is just your sample code, I'm not providing any other information here

@pjsg
Copy link
Author

pjsg commented Mar 16, 2022

I did post a message on the forum, but that has no traction: https://esp32.com/viewtopic.php?f=13&t=26663&sid=b9ec90deb3701f18c7e782242527c4a2#

@Alvin1Zhang
Copy link
Collaborator

Thanks for reporting.

@espressif-bot espressif-bot added the Status: Opened Issue is new label Apr 12, 2022
@github-actions github-actions bot changed the title The IDF websocket server does not handle multiple simultaneous connections (at least the example doesn't) The IDF websocket server does not handle multiple simultaneous connections (at least the example doesn't) (IDFGH-7162) Apr 12, 2022
@chegewara
Copy link
Contributor

Thats correct, this example is not ready to handle multiple connections.
WS is using fd for every connected client and you have to keep tracking every fd since connection till disconnection and publish messages using active fd.

  • fd - file descriptor

@pjsg
Copy link
Author

pjsg commented Apr 13, 2022

Just to be clear, are you saying that the example is broken and that the IDF core code is correct?

@chegewara
Copy link
Contributor

chegewara commented Apr 13, 2022

As far as i know it works perfectly fine. Of course i may be wrong.

My suggestion is to add log after this line to see value of resp_arg->fd:
https://github.com/espressif/esp-idf/blob/master/examples/protocols/http_server/ws_echo_server/main/ws_echo_server.c#L59

@ESP-YJM
Copy link
Collaborator

ESP-YJM commented Apr 15, 2022

@pjsg Could you please try this patch. I test it with your tool and it is ok.
ws_server.zip

@espressif-bot espressif-bot added Status: In Progress Work is in progress Awaiting Response awaiting a response from the author and removed Status: Opened Issue is new labels Apr 15, 2022
@pjsg
Copy link
Author

pjsg commented Apr 19, 2022

Thanks for this. I'll try and test it over the next couple of days.

@pjsg
Copy link
Author

pjsg commented Apr 30, 2022

I'm sorry that it took me so long -- but that patch works great and fixes my problem (the Lua nodemcu firmware).

When will it get merged?

@Alvin1Zhang Alvin1Zhang removed the Awaiting Response awaiting a response from the author label May 5, 2022
@Alvin1Zhang
Copy link
Collaborator

Thanks for sharing the updates, we have a fix under internal reviewing, and the issue will close automatically once the fix is available on GitHub, thanks.

@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 May 6, 2022
@Alvin1Zhang
Copy link
Collaborator

Alvin1Zhang commented May 16, 2022

Thanks for reporting and sorry for slow turnaround, fix is available at b3ab2c6 and fix on release/4.4 is available d72ba54. Feel free to reopen.

@AnkDhage
Copy link

Even I am trying to handle diff channels thru idf ws server, it does not work

@ESP-YJM
Copy link
Collaborator

ESP-YJM commented Dec 22, 2023

@AnkDhage Do your problem is the same as the issue mentioned? Could you give a detailed description about it?

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

6 participants