-
Notifications
You must be signed in to change notification settings - Fork 10
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
Getting OOM when reconnecting socket #8
Comments
I can't see your whole code but this alone looks like it may cause your code to continuously create additional connections until OOM, once you had the first successful connect.
In that case the client connections find no reason to close. New ones keep getting created when token_conn_count hits 10. |
Okay, little different method: I should probably wait for a response before trying to reconnect. So I need to set token_connect true when I receive a connection error:
I have been using callbacks like LWS_CALLBACK_CLOSED and SYSTEM_EVENT_STA_GOT_IP but how do I get LWS_ERRNO from client-handshake.c in a callback so I can try the connection again? |
I think you are missing the point... once you opened a connection, why would it ever close? But your code keeps opening new connections at intervals. So there is an OOM eventually... resetting the server forces all your open connections to close, avoiding the OOM... You don't need to know errno, lws will retry the connect if the error is nonfatal, else inform you with |
Okay I see why there is an OOM. I don't think it retries the connection because I don't see Why do I no longer get |
It retries the accept you showed erroring out, if nothing fatal happened. You must do whole reconnects in the way you have been, but with a bit more care tracking the state of any existing connect. The accept and particularly SSL_accept() are multistep things requiring network roundtrips. Because LWS is nonblocking, things like accept() that normally just stall your thread until they complete return immediately and need to be retried later. LWS takes care of that for you. WRITEABLE only comes when you got a successful connection, and asked for it. |
Thank you for clarification and patience. I added a connect flag back to the Problem is Also when you say ask for a connection I assume that means running |
There is a test client example in lws... although this is like the only demo code for ESP32 actually it's all based on normal lws, where there are more examples. https://github.com/warmcat/libwebsockets/blob/master/test-apps/test-client.c what it does is treat the client wsi pointer returned by Note that |
Okay getting close. I'm using your ratelimit function and client wsi pointer as a flag but it's not being set NULL if an attempt was made but the server is not running. Since no connection is made, I also tried setting client wsi point NULL making another attempt if |
I want to reconnect to a socket if it is closed.
So I add a connect flag to LWS_CALLBACK_CLOSED
and that starts lws_client_connect_via_info in main.c
This works when I manually restart my server
However if I leave my server running for a few hours, the socket inevitably closes and reconnecting fails giving "OOM"
Can you tell me how I can auto-reconnect when a socket is closed? It's strange to me that it works when I manually restart the server but not when it happens after leaving it running.
The text was updated successfully, but these errors were encountered: