-
Notifications
You must be signed in to change notification settings - Fork 311
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
base: main
Are you sure you want to change the base?
Conversation
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.
@@ -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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
Several improvements to the use of context-severing strategies in the codebase