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 socket and memory leak on shutdown #12

Merged
merged 1 commit into from
Aug 29, 2024
Merged

Fix socket and memory leak on shutdown #12

merged 1 commit into from
Aug 29, 2024

Conversation

bradbishop
Copy link
Contributor

When the client is shutting down, its likely that the async_connection_process_loop is polling the stream(socket) and input channel futures, and never wakes so that the stop/shutdown channel can be checked.

As a result the async_connection_process_loop task never exits and while not harmful to subsequent connections, the memory associated with the future is never released, and, since the task owns the stream, the socket itself is leaked as well.

The fix provided by this patch is straightforward, simply poll the stop channel future as well.

An even better fix than the one provided here would be to save the task handle future returned by spawn, poll it somewhere (in case it fails), and join the main task to it on shutdown, after the stop channel has been written to.

When the client is shutting down, its likely that the
async_connection_process_loop is polling the stream(socket) and input
channel futures, and never wakes so that the stop/shutdown channel can
be checked.

As a result the async_connection_process_loop task never exits and while
not harmful to subsequent connections, the memory associated with the
future is never released, and, since the task owns the stream, the
socket itself is leaked as well.

The fix provided by this patch is straightforward, simply poll the stop
channel future as well.

An even better fix than the one provided here would be to save the task
handle future returned by spawn, poll it somewhere (in case it fails),
and join the main task to it on shutdown, after the stop channel has
been written to.
@HsuJv HsuJv merged commit a427dc2 into HsuJv:main Aug 29, 2024
5 of 6 checks passed
@HsuJv
Copy link
Owner

HsuJv commented Aug 29, 2024

Thanks for the contribution. I'd have another release after the clippy fix.
BRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants