Skip to content

WIP: Prevent crash on WebSocket request to non-WebSocket node. - #106

Draft
MauAbata wants to merge 1 commit into
fhessel:masterfrom
MauAbata:bugfix/ws-upgrade-no-ws-route
Draft

MauAbata wants to merge 1 commit into
fhessel:masterfrom
MauAbata:bugfix/ws-upgrade-no-ws-route

Conversation

@MauAbata

Copy link
Copy Markdown

This provides a partial fix for #51 to prevent the Guru from having to meditate. It's been tested on ESP32.

This now checks the HTTPNode type if a WebSocket was requested and only proceeds if the node is in fact a WebSocket, thus preventing the newHandler() call from failing on normal HTTP nodes.

TODO

Right now I'm calling raiseError(404... because that was the first copypaste I can find. I'm not actually sure the best way to reject the websocket connection as I'm not familiar with this library (just picked it up yesterday). This code is sufficient to move the crash over to the client side, which reports a bad frame header now.

A proper rejection should be sent, however that is accomplished in WebSocket land.

Testing

  1. Clone and run the WebSocket chat server example from the master branch, and use https://www.websocket.org/echo.html to connect to the root URL on the device. This should panic and reset your ESP32. Connecting to /chat should work as expected.

  2. Check out this PR and do the same. The ESP32 should no longer panic, and report the rejection of non-WebSocket request.

gb-123-git added a commit to gb-123-git/esp32_https_server that referenced this pull request Jan 23, 2022
Prevent crash on WebSocket request to non-WebSocket node. fhessel#106
gb-123-git added a commit to gb-123-git/esp32_https_server that referenced this pull request Jan 23, 2022
WIP: Prevent crash on WebSocket request to non-WebSocket node. fhessel#106
khoih-prog added a commit to khoih-prog/ESP32_HTTPS_Server that referenced this pull request Sep 27, 2022
Merge some upstream PRs

- Handling of errors - like unstable network - coming via SSL fhessel#89
- WIP: Prevent crash on WebSocket request to non-WebSocket node. fhessel#106
- Fix infinite loop when the buffer ends with \r fhessel#123
- Fixed memory leak in the Websocket example fhessel#157
This was referenced Sep 27, 2022
khoih-prog added a commit to khoih-prog/ESP32_HTTPS_Server that referenced this pull request Sep 27, 2022
1. Merge some upstream PRs

- Handling of errors - like unstable network - coming via SSL fhessel#89
- WIP: Prevent crash on WebSocket request to non-WebSocket node. fhessel#106
- Fix infinite loop when the buffer ends with \r fhessel#123
- Fixed memory leak in the Websocket example fhessel#157

2. Update examples and `README.md`
khoih-prog added a commit to khoih-prog/ESP32_HTTPS_Server that referenced this pull request Sep 27, 2022
1. Merge some upstream PRs

- Handling of errors - like unstable network - coming via SSL fhessel#89
- WIP: Prevent crash on WebSocket request to non-WebSocket node. fhessel#106
- Fix infinite loop when the buffer ends with \r fhessel#123
- Fixed memory leak in the Websocket example fhessel#157

2. Update examples and `README.md`
khoih-prog added a commit to khoih-prog/ESP32_HTTPS_Server that referenced this pull request Sep 27, 2022
1. Merge some upstream PRs

- Handling of errors - like unstable network - coming via SSL fhessel#89
- WIP: Prevent crash on WebSocket request to non-WebSocket node. fhessel#106
- Fix infinite loop when the buffer ends with \r fhessel#123
- Fixed memory leak in the Websocket example fhessel#157

2. Update examples and `README.md`
@rljonesau

rljonesau commented Sep 21, 2026 •

Copy link
Copy Markdown

Having just gone through this myself, I can concur that the fix is valid.
In my case, my default handler was file serving from the file system, opening a websocket to a non defined websocket path -> default handler -> Kaboom.

I arrived at the same code, but made mine a touch more elegant by adding a getMatchingWSNode() to the resolver.
This extra function returns null if the websocket check fails (by the same check).

It just made the front end code a bit cleaner than in the proposed patch.

BUT ALAS, all for nought - one simply has to patch there own code now as they prefer to deal with this as it is no longer supported. :-(

image

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

2 participants