Skip to content

p2plimits: clear the busiest-stream gauge for every transport it reported - #948

Open
ersinkoc wants to merge 1 commit into
google:mainfrom
ersinkoc:audit/p2plimits
Open

ersinkoc wants to merge 1 commit into
google:mainfrom
ersinkoc:audit/p2plimits

Conversation

@ersinkoc

Copy link
Copy Markdown

StreamPressure.observe reset only quic-v1 and tcp before each sample. The router listens on WebSocket, WebTransport and WebRTC as well, and the node uses libp2p's default transports, so when the last connection of one of those closed its stream count stayed on the busiest-stream gauge for good, since nothing wrote that label again.

The sampler now remembers every transport the gauge has a value for and sets it back to 0 when none of its connections is left. TestStreamPressureClearsATransportWithNoConnectionLeft failed on the previous code (busiest websocket after its last connection closed = 7, want 0).

go test -race ./internal/p2plimits/ ./internal/router/ ./internal/node/ and go vet pass on Linux.

…rted

observe reset only quic-v1 and tcp before each sample. A WebSocket,
WebTransport or WebRTC connection that closed left its stream count on
the gauge for good, since nothing wrote that label again. Remember every
transport the gauge has a value for and set it back to 0 when none of
its connections is left.
@ersinkoc
ersinkoc requested a review from aojea as a code owner November 25, 2026 20:30

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a fix to ensure that stream pressure metrics for transports other than QUIC and TCP correctly fall back to 0 when their last connection is closed. It adds a reported map to track previously reported transports, resets their busiest counts to 0 at the start of an observation, and updates the mutex locking to protect this new state. A corresponding unit test, TestStreamPressureClearsATransportWithNoConnectionLeft, has been added to verify this behavior. I have no feedback to provide as the changes are well-implemented and include appropriate test coverage.

This branch has not been deployed

No deployments
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.

1 participant