-
Notifications
You must be signed in to change notification settings - Fork 101
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
Library does not handle server/network failure (disconnect basically). #14
Comments
Hi, Are you sure it evens connect to the server? Looks like you are using SSL but you never provide a certificate.. Can you share the full serial output? Also, Also, if you could turn on debug logs and share those here, it might help. Thank you, |
Hi, I’m pretty sure I was connected, as I was able to (send and) receive messages in the Serial output, while I was writing them in the other endpoints (Firefox, Chrome clients). However, as told, when I shut down the nginx server, nothing happened. I was still in the client.available() loop, while the other endpoints did notice the disconnect. No other event was triggered. Regarding providing a certificate... usually this part is server-side handled (I mean, nginx handles this)... I didn’t know is needed to provide it on the client side as well, as the CA is public. (most implementations go this way). Anyway, the thing is I was connected. I will provide you a screen recording later so you can see. Hope it helps, |
That's so odd. During SSL handshake the client usually wants to validate the server's certificate, in esp8266's WiFiClientSecure you can either choose not to do it (trust that the server is the one you want to talk to) or use a fingerprint. In esp32's implementation (which I of course relay on) you have to provide a certificate and chain validation is mandatory as far as I know. If you use SSL to communicate with the proxy server you still should be required to provide a certificate in order to validate that you are indeed communicating with the right endpoint. Web clients usually has some bank of known root Certificate Authorities they can use to validate any certificate, esp32 does not. I consider this a bug, I will look into it properly this weekend. I will appreciate any help (links and info) about setting up the same server setup as you use. Gil. |
Unfortunately, unlike ESP8266, on ESP32 I don't have an option menu from which I can turn on Debugging. At least not in Arduino IDE, so I'm not really sure how to do it. The configuration file of the nginx server (which behaves as a proxy for the SSL implementation):
In my configuration, I'm running nginx 1.12 compiled with OpenSSL under Debian 9. As a test for chat implementation, I'm using a fork this draft: https://github.com/sanwebe/Chat-Using-WebSocket-and-PHP-Socket . I've tested it today with a public WebSocket server as well ( https://www.websocket.org/echo.html -- which is SSL ) and I can connect without any issue, without having ESP32 asking for any CA or issuing any error. I noticed a difference though: if you cut out WiFi to ESP32, Let me know if I can help you with anything else, Best, |
Great, the information is super helpful! One last question: does this (zombie state) happen when you shut down the nginx server or when you shut down the websockets server behind it? Or both? Gil. |
Mhm, great question you had; just tested: only when I shut down nginx . If I shut down the server behind it (the PHP Socket implementation in my case), ESP32 does notice and Also, I tried re-starting nginx , but ESP32 doesn't notice; so connection is lost at some point... but still Let me know if you want any more testing on anything. Later edit: Anyway, that's odd... you would expect it to happen exactly vice-versa. At least from my point of view. |
Ok so now I'm not on mobile and can expand my thoughts on this. For connectivity checking I relay on the built-in WiFiClient from the esp32 platform libraries. What I believe is happening is that closing the proxy does not send a websockets close message, but only closes the TCP connection which the WiFiClient (library) does not handle properly.
That is an unwanted-behavior for sure, first thing I will address is the callback not being called when availability changes states. You should know how-ever that the event callback is for websockets events. So if no callback is being called, its probably because no Second thing I will try to address is a websockets connection over a proxy and the scenarios you described. Third thing is certificates on esp32. From what I know you can't connect without setting a CA, but you seem to have no problem, so either the library changed or something else is going on. Thank you for the detailed issue, I might split this into several other issues in-order to better track tasks. Gil |
UPDATE: I've fixed the Regarding the nginx issue, I believe the problem is inherited from esp32's What you can do: you can try doing an "active available call". Basically, send a ping before calling available. That should test the TCP connection and the esp32 will notice that something isn't right. Available should return false and an event will be triggered. You can either do it manually by calling if(client.available(true)) {
// code...
} Notice that if you have no delay between calls to Sadly, there isn't much I can do about this issue. You could however open an issue on espressif's github. Can you do those 2 extra things:
Thank You, |
Testing done, both ESP8266 and ESP32. ESP8266: Library notices if the nginx proxy server goes down, no matter if ESP32: Library notices that nginx proxy server goes down, ONLY when using Attached are 3 LOGS for all the situations and the used code for testing. As said, didn't test debug_esp32_client_available_true.txt By the way, in the ESP32 log, you'll find surprisingly information about SSL, but that's another story.
Regarding our issue, right now I'm looking forward to see what can be done to the WiFi.h compared to Esp8266Wifi.h, as it seems - as you said too - there lies the problem. I'm looking forward for the fastest way address this. Anyway, I appreciate your time for addressing these issues, this library is really important to me; hope I will be able to support your work one day, if my on-going project succeeds :) (right now, I'm building something from scratch from my own time & funds). Let me know if you have feedback on the attached logs (including the SSL part), |
I'm glad to hear that this library is important to you. It is important to me aswell and seeing other users using it and helping to improve it makes me really happy. Openning this issue is very helpfull, and is the only kind of support I need 😃 A note: consider using active Thank you for the kind words and the detailed issue. I have merged the changes into the master branch and advanced to a new patch. I will keep the branch open so I will remember looking into the SSL logs. If you don't mind, I will also tag this as resolved. Thanks again and good luck with your project! Best wishes, |
Hi Gil, Sorry for the delayed-reply, weekend caught me way too long this time... (and is Tuesday already) :D . Yes, somehow I'll find a solution using periodical calls to the client.available(true) call. I'm determined to use your library as it completely fulfills my needs. Hope in the near future Espresiff will also fix the issue in the WiFi library. I would want to open an issue on their Github page regarding this, but the only thing standing in my way is the fact that I'm not really sure how to describe the issue without going into the Sockets library story, as I'm afraid they won't care when I'll mention the fact that I'm using another library to trigger the issue. Thank you as well and once again for the work you've put in all this project, really helpful for me and I'm sure for other people too! When my project will be a successful one, I won't forget your name :)) All the best, |
The discussion continued on #18. |
Hi Gil, I'm having a related issue with latest (0.5) library. I am connecting to a Red digital cinema camera that has a websocket server in it - though I have no access or control to that server - it's sealed up inside the camera. Everything is working really well to send and receive websocket data to the camera. However, like the OP, when I power down the camera, remove the wifi connection to the camera, or otherwise break the TCP connection, client.available() is not returning false, even when doing a manual client.ping before client.available. Pongs stop coming back, but available still returns true. Am I doing something wrong to force an availability check? I'm using an esp8266 (ESP-12E). And am currently using the example to test this issue:
|
Hi @mikegoubeaux , Just a tip (for now, as I don't have the necessary time to dive into code at the moment):
If you indeed get the On my end, with ESP8266 I managed to get the status correctly all the time. Only ESP32 caused troubles. Hope it helps, |
Thanks @gilmaimon ! Great suggestion on ArduinoTimer, I am using it to call I'm calling Sure you're busy, but not sure where to go from here. LOVE the library. Thanks for all of your great work. |
Hi,
I'm using the code from the Client Example for an SSL server.
Most of it works as expected, however - if I shutdown the WebSocket server I'm connected to or even disconnect the network, no event is being triggered.
Surprisingly, even if i call
client.available()
it returnstrue
, even though the server is shut down or there's no network connection to it...I'm using an ESP-WROOM-32 board if and an NGinx WebSocket server. The socket server works without any issue with any browser client (tested EDGE, Firefox, Chrome) and these browsers successfully report a server disconnect or so.
As told, code is the one from the client example:
If there's any detail I can help you with to debug this issue, just let me know.
All the best,
A.
The text was updated successfully, but these errors were encountered: