-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
Heap leak on tcp socket closing (IDFGH-8173) #9670
Comments
There is a pull request targeting the same issue: espressif/esp-lwip#63. |
Just wanted to comment that we've also had reports of problems from too many sockets in TIME-WAIT, which this bug enables. If connections are short-lived and rapid then you can easily end up with hundreds of sockets in TIME-WAIT state, rather than limited to |
Hi Angus, I can confirm that the current lwIP doesn't properly limit the number of active PCBs. Here's a preliminary patch that should resolve this, we'll fix this soon. I'm sorry the inconvenience. |
Hi @david-cermak, nice to hear from you again! Appreciate the update and the patch, I know you folks are always busy. For MicroPython's specific purposes we have our own patch now (PR is linked above), which basically uses a linker wrap to do the same thing as your patch - so we're good until this gets fixed upstream. 👍 |
Answers checklist.
General issue report
When frequently open and close tcp sockets, anytime there are heap leakage by sizeof(struct tcp_pcb).
This is because the socket remains in the state TIME-WAIT.
Must be: When allocating a new socket, if the value is exceeded CONFIG_LWIP_MAX_ACTIVE_TCP (MEMP_NUM_TCP_PCB), the oldest socket in the state TIME-WAIT must be released.
Code from lwip:
What really: if MEMP_MEM_MALLOC=1 (by default), the value of CONFIG_LWIP_MAX_ACTIVE_TCP (MEMP_NUM_TCP_PCB) does not matter (not used in memp functions), and new sockets will be placed any time when calling tcp_alloc until the heap is zeroed out. And tcp_kill_timewait(); will call only when all ESP heap will be close to 0 (then memp_malloc(MEMP_TCP_PCB) will return NULL on allocation fails)
Setting MEMP_MEM_MALLOC=0 solves this issue, but there appears runtime issue with MEMP_NUM_SYS_TIMEOUT value (increasing this value solves this problem).
The text was updated successfully, but these errors were encountered: