-
Notifications
You must be signed in to change notification settings - Fork 138
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
websocket client loses first text message when packed together with http response (IDFGH-11300) #396
Comments
I'm seeing this using ESP websocket client to connect over WSS to an Engine.IO server. After the initial connection, the Engine.IO protocol sends a packet to the client(Engine.IO open(EIO ID=0)), and that packet sometimes goes missing when it is returned over HTTP just before the handover to websocket. Here's logging of it working, as it usually works:
But sometimes the EIO Connect is returned over HTTP just before the protocol switch, and thus dropped:
I think the issue may be in transport_ws, rather than esp-websocket-client, since that's where the message is pulled over TLS, and dropped. 0xFEEDC0DE64's workaround doesn't seem to be an option for our server. |
@gabsuren , it looks like this hasn't been touched in a bit. Is there anything we could do to help? In the event of an HTTP response during the upgrade, do we need to parse it and emit the event just after the connect event is processed? |
@rsaxvc actually the fix has already been submitted for review and is expected to be merged shortly, likely within this week. Apologize for the delay |
@0xFEEDC0DE64 @rsaxvc The fix is already available in ESP-IDF latest master branch. Thank you |
Been testing the last two days - haven't seen our printout when we detect the dropped EIO.Open, so it seems to be working. I should add a printout when the EIO.Open is routed over HTTP rather than WS to be certain though. |
Closing the issue as the fix already available in espressif/esp-idf@2267d4b, please don't hesitate to reopen this if you encounter any further problems. Thank you! |
I finally caught it with a few printouts when EIO.Open was routed over HTTP before the WS changeover. The results were unexpected. @gabsuren I don't think I can reopen though. My annotations with '#':
If I understand the patch correctly, when there is a response delimiter present, memmove() the start of response over to the start. However, server_key is a pointer, not a copy, so the memmove can shift data over the server-key. When I diff the keys:
I see they both have a suffix of |
Perhaps we should check the server-key;first, before shifting over the response data? |
@gabsuren , I have a patch for this here: https://github.com/bryghtlabs-richard/esp-protocols/tree/pr-ws-fragfix which defers shifting the response over the headers until after the server-key is validated. I'm having trouble creating a pull-request though - github isn't seeming to parse the common commit ancestor. |
@bryghtlabs-richard Thank you for your contribution. I will create a new pull request incorporating your commit. |
Please don't submit yet - we're having some connection issues here, we think they're on the server, but unable to test here for now. Edit: this is a bug in my client-side patch that is only triggered when "Sec-WebSocket-Accept" is the last header in the response. |
When first fragment is sent over HTTP during websocket connection, defer buffering of fragment until after the websocket server-key is validated. This order is required because the first fragment buffering overwrites the memory holding the server-key headers. Fixes 2267d4b Fixes espressif/esp-protocols#396 PR #13724
When first fragment is sent over HTTP during websocket connection, defer buffering of fragment until after the websocket server-key is validated. This order is required because the first fragment buffering overwrites the memory holding the server-key headers. Fixes 2267d4b Fixes espressif/esp-protocols#396 PR #13724
@bryghtlabs-richard the changes has been merged to ESP-IDG Github. Thank you for your contirbution |
Thanks @gabsuren |
When first fragment is sent over HTTP during websocket connection, defer buffering of fragment until after the websocket server-key is validated. This order is required because the first fragment buffering overwrites the memory holding the server-key headers. Fixes 2267d4b Fixes espressif/esp-protocols#396 PR #13724
When first fragment is sent over HTTP during websocket connection, defer buffering of fragment until after the websocket server-key is validated. This order is required because the first fragment buffering overwrites the memory holding the server-key headers. Fixes 2267d4b Fixes espressif/esp-protocols#396 PR #13724
Answers checklist.
General issue report
I need to first flush in my websocket server, before sending the first websocket text message, otherwise the websocket client on the ESP32 doesnt report the text message. All following text messages are received then correctly, just my hello message is missing in ESP32
The text was updated successfully, but these errors were encountered: