Skip to content

fix(server): Use tokio::select when waiting for connection close/global graceful shutdown - #30

Open
thesw4rm wants to merge 4 commits into
linkerd:mainfrom
thesw4rm:fix-serve-conn-leak
Open

thesw4rm wants to merge 4 commits into
linkerd:mainfrom
thesw4rm:fix-serve-conn-leak

Conversation

@thesw4rm

@thesw4rm thesw4rm commented Oct 7, 2026 •

Copy link
Copy Markdown

Solves linkerd/linkerd2#15684

BUG

Connections were not being dropped from memory after being closed. server_conn was waiting on a release shutdown signal. This was a regression likely caused by the hyper 0.14 to 1 bump in a95478a

FIX

Switch back to a tokio::select pattern. Branch predictor is optimized to check the connection being closed first, before polling for a shutdown signal.

Signed-off-by: Yadunandan Pillai contact@mail.thesw4rm.com

@raykroeker

Copy link
Copy Markdown
Member

Thanks for sending the PR. Some feedback to consider:

  1. Housekeeping. Have a look at the sign-off in CONTRIBUTING.md and DCO it'd be great to signoff on all commits.
  2. Given we're no longer using graceful, drop the feature from Cargo.toml.
  3. The version change to Cargo.lock isn't tied to this change.
  4. Add some testing that demonstrates the validity of the tokio::select pattern.

@raykroeker raykroeker self-assigned this Oct 8, 2026
@thesw4rm
thesw4rm force-pushed the fix-serve-conn-leak branch 6 times, most recently from 555de8d to ccace6d Compare October 8, 2026 23:37
@thesw4rm

thesw4rm commented Oct 8, 2026 •

Copy link
Copy Markdown
Author

@raykroeker

Appreciate it!

1, Signoff passes DCO now.
2. Graceful is dropped from Cargo.toml
3. Cargo.lock looks like it is out of sync. My build keeps changing it. I've kept it 0.26.0 for now, but kubert package is 0.27.0
4. Unit tests added. They consistently fail on the old pattern, and pass on the new one. I'm not sure that this test should be kept in there though. The bug in the previous code was, from what I've understood, a one-off instance rather than behavior we expect to see again.

The earlier pattern came as a result of the upgrade from Hyper 0.14 to
Hyper 1.x. We were blocking on the global shutdown signal after each
connection, causing the connection structs to stay allocated in memory.
Over a flood of many connections (even after they close), this was
causing significant memory leaks.

Signed-off-by: Yadunandan Pillai <contact@mail.thesw4rm.com>
Signed-off-by: Yadunandan Pillai <contact@mail.thesw4rm.com>
Signed-off-by: Yadunandan Pillai <contact@mail.thesw4rm.com>
@thesw4rm
thesw4rm force-pushed the fix-serve-conn-leak branch from ccace6d to 8ce4f15 Compare October 8, 2026 23:55
@thesw4rm thesw4rm changed the title Use tokio::select when waiting for connection close/global graceful shutdown fix(server): Use tokio::select when waiting for connection close/global graceful shutdown Oct 9, 2026
@thesw4rm

thesw4rm commented Oct 9, 2026 •

Copy link
Copy Markdown
Author

Hey @raykroeker . Looks like the issue reporter confirmed that linkerd/linkerd2#15684 is likely directly related to the fix (same reproduction steps).

They're not comfortable building their own image. Do you think this PR is ready to merge, so they can confirm the fix on their end?

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yadunandan Pillai <contact@mail.thesw4rm.com>
@thesw4rm

Copy link
Copy Markdown
Author

@raykroeker bumping this one, if you've got the time!

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