Skip to content
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

fix(mem): Fix memory leak in _accept() functions when _accept is called with a null pcb #25

Merged
merged 1 commit into from
Feb 8, 2025

Conversation

mathieucarbou
Copy link
Member

@mathieucarbou mathieucarbou commented Feb 7, 2025

Fix inspired by PR #21 from @willmmiles

AsyncTCP had a memory leak when receiving too many requests, even if the queue length is increased (256 in my testing). The problem was in the handling of the _accept function which was not handling all the possible use cases.

To reproduce, in main branch, trigger 3 times:

autocannon -c 32 -w 32 -a 96 -t 30 --renderStatusCodes http://192.168.4.1

You should see a log similar than this one:

device-monitor-250207-213547.log

In my case, starting at

Uptime: 2 s, requests: 0, Free heap: 236932

Ending at:

Uptime: 220 s, requests: 192, Free heap: 207624

With this fix, you should see a log similar to this one:

device-monitor-250207-222548.log

[165298][E][AsyncTCP.cpp:1659] _accept(): _accept failed: pcb is NULL

This is the use case that was not handled before and was causing a leak 👍

@mathieucarbou mathieucarbou self-assigned this Feb 7, 2025
@mathieucarbou mathieucarbou requested a review from a team February 7, 2025 21:35
@mathieucarbou mathieucarbou changed the base branch from logs to main February 7, 2025 21:39
@mathieucarbou mathieucarbou changed the title fix(mem): Fix memory leak in _accept() functions where aborted requests were not correctly cleaned up fix(mem): Fix memory leak in _accept() functions when _accept is called with a null pcb Feb 7, 2025
src/AsyncTCP.cpp Outdated Show resolved Hide resolved
src/AsyncTCP.cpp Outdated Show resolved Hide resolved
@mathieucarbou
Copy link
Member Author

@vortigont : based on your suggestion, I have updated the PR to directly call tcp_abort. Tested again, works fine :-)

I will let you approve and merge the PR, thanks!

@vortigont vortigont merged commit 1ac4571 into main Feb 8, 2025
13 checks passed
@mathieucarbou mathieucarbou deleted the leak branch February 8, 2025 12:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants