Skip to content

[HTTP] Share observable metrics per meter - #136493

Open
asad24-dev wants to merge 1 commit into
dotnet:mainfrom
asad24-dev:fix-http-observable-metrics-136418
Open

asad24-dev wants to merge 1 commit into
dotnet:mainfrom
asad24-dev:fix-http-observable-metrics-136418

Conversation

@asad24-dev

Copy link
Copy Markdown
Contributor

Fixes #136418.

Summary

Each SocketsHttpHandler currently creates separate http.client.active_requests and http.client.open_connections observable instruments, even when the handlers share a meter. Since observable instruments are not cached by Meter, this registers additional callbacks for each handler.

This change shares the observable instruments and their trackers per meter. Instrument initialization is synchronized to avoid duplicate registrations when handlers are created concurrently.

The existing metric names, tags, units, descriptions, and histograms are unchanged.

Tests

Added regression coverage for:

  • Instrument registration across sequential and concurrent handlers.
  • Active-request aggregation across handlers.
  • Handler disposal while another handler remains active.
  • Completion of in-flight requests after handler disposal.

Validated against current main:

  • Instrument uniqueness: 2/2 passed.
  • Aggregation and disposal: 4/4 passed.
  • General HTTP metrics: 8/8 passed.
  • HTTP/1.1 metrics: 49/49 passed.
  • HTTP/2 metrics: 40/40 passed.

The functional-test project builds successfully.

The full functional suite was not rerun. A previous run encountered MsQuic loading failures in HTTP/3 tests and a separate timeout in the test environment.

Observable HTTP instruments are not cached by Meter, so each handler registers additional callbacks on the shared meter. Share the instruments and their trackers per meter instead.

Fixes dotnet#136418
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Oct 26, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@unsafePtr

Copy link
Copy Markdown
Contributor

@asad24-dev, if you're interested in working on this, please take a look at my changes in #136849. Your current PR is failing the build and tests for WASI. Adding a lock here seems excessive. Please backport my changes, and I'll close my PR.
cc @ManickaP

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

area-System.Net.Http community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.Net.Http: observable http.client.active_requests / open_connections leak two instruments per handler (regression from #131275)

3 participants