-
Notifications
You must be signed in to change notification settings - Fork 183
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
EspHttpServer: function in ws_handler gets called on any other http request #348
Comments
Possibly related upstream issues: espressif/esp-idf#11097 |
|
Sure, it's at https://gitlab.com/IvanSanchez/solanera . But beware that this is my "learning rust" project, so I'm not really proud of code quality. |
Actually, I checked the bug twice and I'm changing my mind. There's a chance that it might be the root cause, I just can't believe it happens on the first hit by curl. Maybe you are oversimplifying the story? Anyway and regardless. Thinking loud now: Looking at how long it took the Espressif folks to suggest a (non-working) workaround, I don't think this issue would be fixed soon. Maybe this is the reason I did not catch this problem earlier e.g. here. If you look how I'm processing the websocket connections, if the WS connection is reported as closed by the server, yet it is not in my list, I just discard it. So why don't you try just that and see if it gets you somewhere? |
BTW I'm digressing, but... this loop will block the HTTP server from processing anything else besides your just-created web-socket. Reason: the ESP IDF HTTP server is single threaded. |
...not really. I've simplified the code because of course I'm raising the wifi interface before starting the webserver and registering half a dozen handlers for GETs and not just one, but I cannot see how that might impact the situation. The WS connection is handled at the first curl request, though.
After realizing my fumble with the WS loop, I'm not fully sure. But having a WS handle do work on connections that are not WS connection adds quite a lot of undefined behaviour - I have no way of knowing if a
On a side note, that sounds like something that should be in the docstrings ;-) |
You are mixing up things. The fact that the server is single threaded has nothing to do with the problem at hand.
Maybe. Or maybe not. Not sure how knowing that the server is single-threaded would help you. What I mean is that even if the server was multithreaded, the |
What I meant to say is: I was experiencing HTTP requests hanging indefinitely (HTTP request triggers a WS handler that loops infinitely waiting for a frame to be sent). After being aware of the single-threaded nature of
My brain is poisoned by too much Javascript. Which means that my first instinct is to think that everything is automagically async, and that a request handler spawns its own thread. (In other words: I wrongly believed that somehow, if a request handler blocks, the server will handle other requests). Ideally, documentation would allow other people like me not make the wrong assumptions. OTOH: I'm aware that WS offers duplex capabilities. I'm not planning on using them (for now). |
Not sure JS is the best example of a multi-threaded execution at which you are alluding, as JavaScript is single threaded actually and the way it gets around with it is by using promises, which are processed off the single-threaded message loop. And the async/await syntax makes that mostly bearable. But it is not automagic because - you know - it introduces coloring in the language. :p Rust also has async/await, but you probably don't want to get there, if you are just starting with it. As you have to learn lifetimes and trait metaprogramming first. And gazillion of other things, if you haven't yet... Anyway, I'm digressing but the reason why I'm mentioning async/await is because having a single-threaded (or little-threaded) embedded web server... For more complex use cases, I hope my edge-http will pick up steam soon.
Yeah yeah. I think you are overemphasizing it. I might be getting cynical with time, but I think reading code (including ESP IDF C code) is unavoidable. |
I have a HTTP server set up like this:
When I do a just GET request (via e.g.
curl http://esp32_ip_addr:80/index.html
), the serial log looks like:Therefore I must conclude that functions registered with
ws_handler
are called when they shouldn't, even though thews_handler
calls are sending the URI to the underlying esp-idf C lib.For reference, my
Cargo.toml
file contains the following crate versions:And
.cargo/config.toml
contains:Couple of remarks:
cargo run
)/ws
at all, and that I don't have any lingering web browser windows.xtensa-esp32-espidf
targets..cargo/config.toml
to useESP_IDF_VERSION="v5.1.2"
and rebuilding.The text was updated successfully, but these errors were encountered: