Skip to content

Fix PcapngWriter 'Already registered' on ephemeral port reuse - #620

Merged
haga-rak merged 1 commit into
mainfrom
fix/pcap-writer-already-registered
Apr 13, 2026
Merged

haga-rak merged 1 commit into
mainfrom
fix/pcap-writer-already-registered

Conversation

@haga-rak

Copy link
Copy Markdown
Owner

Summary

When the OS reuses an ephemeral local port during the linger tear-down of a previous outbound capture, DirectCaptureContext.Subscribe collided on the connection 5-tuple key and called PcapngWriter.Register a second time on an already-registered writer, throwing InvalidOperationException: Already registered!.

Fix rotates the stale writer in Subscribe and decouples the subscription id (lifecycle) from the 5-tuple key (packet routing). SyncWriterQueue now holds two dicts and TryRemoveBySubId only removes by key when instances still match, so the old connection's linger-delayed Unsubscribe is a safe no-op after rotation.

No change to ICaptureContext shape or the out-of-proc wire protocol.

Rotate stale writer in DirectCaptureContext.Subscribe and decouple
subscription id from 5-tuple so a linger-delayed Unsubscribe of the
previous connection no longer yanks the new writer.
@haga-rak haga-rak added the bug Something isn't working label Apr 13, 2026
@haga-rak
haga-rak merged commit f7d669d into main Apr 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant