Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use an atomic.Int64 as bodyWrapper read bytes counter #5080

Merged
merged 3 commits into from
Feb 13, 2024

Conversation

dmathieu
Copy link
Member

Closes #4895.

This switches the bodyWrapper struct to use an atomic.Int64 instead of a plain int64 integer to count read bytes.
This should solve the race condition mentioned in #4895, though unfortunately, this isn't being tested as I haven't been able to reproduce the issue within the codebase.

@dmathieu dmathieu requested a review from Aneurysm9 as a code owner February 12, 2024 12:55
@dmathieu dmathieu requested a review from a team February 12, 2024 12:55
Copy link

codecov bot commented Feb 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ee76330) 79.6% compared to head (cf65189) 79.6%.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #5080   +/-   ##
=====================================
  Coverage   79.6%   79.6%           
=====================================
  Files        152     152           
  Lines      10511   10511           
=====================================
  Hits        8371    8371           
  Misses      1944    1944           
  Partials     196     196           
Files Coverage Δ
instrumentation/net/http/otelhttp/handler.go 87.3% <100.0%> (ø)
instrumentation/net/http/otelhttp/transport.go 96.9% <100.0%> (ø)
instrumentation/net/http/otelhttp/wrap.go 92.5% <100.0%> (ø)

@MrAlias MrAlias merged commit 43ec73b into open-telemetry:main Feb 13, 2024
22 checks passed
@dmathieu dmathieu deleted the bodywrapper-atomic-read branch February 13, 2024 15:53
zailic pushed a commit to zailic/opentelemetry-go-contrib that referenced this pull request Feb 13, 2024
…#5080)

* use an atomic.Int64 as bodyWrapper read bytes counter

* add changelog entry

---------

Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
@ash2k
Copy link
Contributor

ash2k commented Feb 13, 2024

I think this fix may lead to incorrect metric reported, see my comment here #4895 (comment). This can be checked by having a reader for the body that is slow+a big body and a server that starts responding without consuming all of the incoming request's body.

@MrAlias
Copy link
Contributor

MrAlias commented Feb 13, 2024

I think this is still as improvement worth including. Slightly incorrect data is better then a panic.

Please do submit a change to address the data inconsistency you mention.

@ash2k
Copy link
Contributor

ash2k commented Feb 13, 2024

I agree this is an improvement vs a data race. I'm not planning to work on this, but I've opened an issue so that this is not lost and someone can pick it up #5087.

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.

Data race in v0.48.0
5 participants