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
LwIP socket: unwanted behaviour and memory leak after "pulling-the-plug" event (IDFGH-7051) #8668
Comments
Show your modifications |
Updated issue description with added server code used to shutdown unwanted (dead) socket connection. |
Hi, |
Hi, |
@ChrisHul I think you shoud add mechanisms for detecting zombie clients in server side, you can use MQTT PING/PONG packet or TCP keepalive. For the memory leak, can you tell more details about how to reproduce and try many times in your local to test it, check it whether execute about 100 times will occupy about large memory. |
@ChrisHul I may have found a solution of myself. |
Thank You both @sramrajkar and @ESP-YJM for sharing your thoughts, Politically I agree fully with @ESP-YJM in the view of regarding the MQTT protocol as the primary responsible for time-out issues. Unfortunately Mongoose does not support MQTT time-out and will only respond to client pinging. Full stop. No timing function is enabled in this software. If there is a better MQTT layer which allows server implementation, please advice. I have also updated the issue description with the server/broker software being used. This is the location where I have applied the modifications mentioned above. Apoligies for not stating that previously. When it comes to the memory leak, I have actually stress-tested the server with a client that resets twice a minute and reconnects. Both short and long-term results indicate that there is a memory leak. Leaving the two devices interacting over the night will produce a heap reduction of 15-20 kB in the server device. Short term I can observe the heap being reduced by an average of 20 bytes every cycle. I have checked the Mongoose memory handling and it seems clean, so I suspect the lwIP component is at fault. I'll be happy to provide further details for reproducing this issue. I consider both suggested fixes as work-arounds and far from ideal. For the time being I prioritize getting my project working. Sorry I couldn't help @sramrajkar, but I wish You good luck with your project. |
@ChrisHul I think you can refer to https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/heap_debug.html?highlight=heap_trace_stop#how-to-diagnose-memory-leaks and add some heap debug. |
@ESP-YJM I did previously check the esp-idf instructions for debugging memory leak issues, but the structure itself of the lwIP socket software is rather overwhelming. Debugging the closure of the socket would include code such as:
where one can assume that the execution is not linear, but deferred to a later occasion, maybe triggered by an interrupt or a timer. This makes it very difficult to pinpoint any code as being susceptible to memory leaks. Memory is being allocated and freed all the time and would rapidly fill up the debugging record if left active over time. |
@ChrisHul Any update for this issue? |
Hi @ESP-YJM ! Not really. Have been working on hardware part and main processor programming. Will check with updated ESP32 software when I return to the networking again. Thanks for shown interest. |
Environment
Problem Description
Expected Behavior
The socket should not stall, but rather raise an error to be detected by caller. In any case it should release allocated memory when closing.
Actual Behavior
The socket connection stalls and leaves behind dead memory if closed. Update: if not closed it resolves with termination code after a very long delay (2 hours).
Steps to reproduce
Terminate the connection abruptly and monitoring the Heap size.
Code to trigger zombie socket shutdown
Mongoose own shutdown trigger
TCP keep-alive time (defaults to 7200) can be changed as follows:
// If your code is longer than 30 lines, GIST is preferred.
Debug Logs
Other items if possible
build
folder (note this may contain all the code details and symbols of your project.)The text was updated successfully, but these errors were encountered: