Skip to content

improvements to context severing #2370

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

vroldanbet
Copy link
Contributor

Several improvements to the use of context-severing strategies in the codebase

The code stems from a misunderstanding with how context
cancelation works: child cancelation is not propagated
upwards to the parent.

This caused downstream queries caused by LR2 not to be canceled
when requested.
This helps making sure that all the values stuffed in
the context are retained without having to recreate all
of it manually
this means we keep all the different components injected
in the context intact, and we only change the cancelation propagation.
@vroldanbet vroldanbet requested a review from a team as a code owner April 28, 2025 19:09
@vroldanbet vroldanbet self-assigned this Apr 28, 2025
@github-actions github-actions bot added the area/datastore Affects the storage system label Apr 28, 2025
@@ -457,7 +457,7 @@ func (ls *parallelLimitedIndexedStream[Q]) forTaskIndex(ctx context.Context, ind
// Create a new cursor with cloned limits, because each child task which executes (in parallel) will need its own
// limit tracking. The overall limit on the original cursor is managed in completedTaskIndex.
childCI := currentCursor.withClonedLimits()
childContext, cancelDispatch := branchContext(ctx)
childContext, cancelDispatch := context.WithCancelCause(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

The previous version severed the context completely - did you mean to write WithoutCancel here?

Copy link
Contributor Author

@vroldanbet vroldanbet May 2, 2025

Choose a reason for hiding this comment

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

I deliberately intended to not sever the context. I couldn't find a reason to justify severed context. This is what prompted this PR: I observed that cancelation wasn't getting propagated to ReverseQueryRelationship calls in the data store, which means we could be not _ freeing resources.

I checked with Joey and he also didn't recall what was the reason, other than a potential misunderstanding around child context propagating cancelation to parents (which is not the case).

But tests are failing so... 🤷🏻‍♂️

@@ -66,15 +47,15 @@ func (p *ctxProxy) IsStrictReadModeEnabled() bool {
}

func (p *ctxProxy) OptimizedRevision(ctx context.Context) (datastore.Revision, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this proxy even used anywhere anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, MySQL datastore still uses it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/datastore Affects the storage system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants