Skip to content

device: set peer to expire unconditionally#73

Open
illotum wants to merge 1 commit into
tailscalefrom
illotum/handshake-leak
Open

device: set peer to expire unconditionally#73
illotum wants to merge 1 commit into
tailscalefrom
illotum/handshake-leak

Conversation

@illotum

@illotum illotum commented Jun 19, 2026

Copy link
Copy Markdown

e3ac4a0 introduced lightweight API that can be used instead of UAPI to reconfigure peers. Peer state created via the new PeerLookupFunc is not set to expire until the handshake succeeds, making device leak two goroutines and a set of buffers for each failed handshake.

This change arms the expiry timer before the handshake gets to proceed.

Updates tailscale/tailscale#20183

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a resource leak for lazily-created peers (via PeerLookupFunc) that never complete a handshake by ensuring the peer expiry timer is armed even if no session is established. This prevents leaked goroutines and buffer retention on failed/non-started handshakes in the device package.

Changes:

  • Arm zeroKeyMaterial expiry for lazily-created peers during Device.LookupPeer.
  • Add a synctest-based unit test to verify lazy peers are reaped after RejectAfterTime*3 even without a successful handshake.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
device/device.go Arms the lazy peer reaping timer during LookupPeer so peers without successful handshakes are reclaimed.
device/failed_handshake_test.go Adds a synctest-based test asserting lazy peers are removed after the expiry deadline.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread device/device.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread device/failed_handshake_test.go Outdated
e3ac4a0 introduced lightweight API that can be used instead of UAPI
to reconfigure peers. Peer state created via the new PeerLookupFunc
is not set to expire until the handshake succeeds.

Device leaks two goroutines and a set of buffers for each failed handshake.
This change arms the expiry timer before the handshake gets to proceed.

Updates tailscale/tailscale#20183

Signed-off-by: Alex Valiushko <alexvaliushko@tailscale.com>
Change-Id: Ibc0abb6eec97aca0a10f50515dea9e0d6a6a6964
@illotum illotum force-pushed the illotum/handshake-leak branch from d942d22 to e83a51f Compare June 19, 2026 02:52
@illotum illotum marked this pull request as ready for review June 19, 2026 03:13
@illotum illotum requested a review from jwhited June 19, 2026 03:14
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