Skip to content

Comments

fix(tracing): use context to pass trace and retrieval state to session#1059

Merged
gammazero merged 3 commits intomainfrom
fix-tracing
Oct 25, 2025
Merged

fix(tracing): use context to pass trace and retrieval state to session#1059
gammazero merged 3 commits intomainfrom
fix-tracing

Conversation

@gammazero
Copy link
Contributor

@gammazero gammazero commented Oct 24, 2025

Trace state, carried in the context passed to NewSession was not being passed into the session. This is fixed by having session.New accept a context that contains trace and retrieval state.

…val state to session

Trace state, carried in the context passed to NewSession was not being passed into the session. This is fixed by having session.New accept a context that contains trace and retrieval state.
@gammazero gammazero requested a review from a team as a code owner October 24, 2025 06:55
@codecov
Copy link

codecov bot commented Oct 24, 2025

Codecov Report

❌ Patch coverage is 76.92308% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.02%. Comparing base (1f0df2e) to head (829895c).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
bitswap/client/client.go 66.66% 2 Missing and 1 partial ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1059      +/-   ##
==========================================
- Coverage   61.06%   61.02%   -0.05%     
==========================================
  Files         268      268              
  Lines       26135    26132       -3     
==========================================
- Hits        15960    15947      -13     
- Misses       8501     8506       +5     
- Partials     1674     1679       +5     
Files with missing lines Coverage Δ
bitswap/client/internal/session/session.go 89.28% <100.00%> (+0.90%) ⬆️
...p/client/internal/sessionmanager/sessionmanager.go 95.08% <100.00%> (ø)
bitswap/client/client.go 76.57% <66.66%> (-1.57%) ⬇️

... and 9 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lidel lidel changed the title fix tracing by using context to pass trace and retrieval state to session fix(tracing): use context to pass trace and retrieval state to session Oct 24, 2025
@gammazero gammazero merged commit 8c17f11 into main Oct 25, 2025
16 checks passed
@gammazero gammazero deleted the fix-tracing branch October 25, 2025 05:02
Comment on lines +449 to +456
// Temporary session closed indepentendly of cancellation ctx.
sessCtx, cancelSession := context.WithCancel(context.Background())

// Preserve retrieval.State from the original request context if present
if retrievalState := retrieval.StateFromContext(ctx); retrievalState != nil {
sessCtx = context.WithValue(sessCtx, retrieval.ContextKey, retrievalState)
}
session := bs.sm.NewSession(sessCtx, bs.provSearchDelay, bs.rebroadcastDelay)
Copy link
Member

Choose a reason for hiding this comment

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

@gammazero do you remember why this is separate session? do we detach if from trace on purpose?

IIUC without passing trace provider discovery operations within this temporary session won't be traced, making debugging harder? Or is this decreasing the noise?

Copy link
Contributor Author

@gammazero gammazero Oct 28, 2025

Choose a reason for hiding this comment

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

I think that a separate context was used for the session, so that the context passes into GetBlocks would only cancel the call to session.GetBlocks and not cancel the session itself. This allows the goroutine created here to cancel/close the session when finished reading blocks.

The purpose of doing this is so that the caller does not have to explicitly cancel the context passed into this function, which otherwise is required to prevent leaking the session created here, since otherwise there is no way to cancel/close the session.

Looking at this code, it introduces a defect in that it prevents the propagation of tracing state carried by the context passed into GetBlocks. This can be fixed by making the passed in context be the parent of the session context, or by simply returning the blocks channel and depending on the caller to cancel the passed in context.

@lidel See #1060 for fix.

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.

bitswap/session: context-aware lifecycle

2 participants