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

Fix mutable state access after workflow lock is released #4333

Merged
merged 2 commits into from
May 15, 2023

Conversation

alexshtin
Copy link
Member

What changed?
Fix mutable state access after workflow lock is released.

Why?
Workflow context and mutable state fields should not be accessed after workflow lock is released.

How did you test it?
Existing tests.

Potential risks
No risks.

Is hotfix candidate?
No.

@alexshtin alexshtin requested a review from a team as a code owner May 12, 2023 22:24
// Wrapping workflow context related operation in separate func to prevent usage of its fields (including any mutable state fields)
// outside of this func after workflow lock is released.
// It is important to release workflow lock before calling matching.
wfCtxOperation := func(wfKey definition.WorkflowKey) (
Copy link
Contributor

Choose a reason for hiding this comment

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

Fine for this PR but if this is going to be the pattern then what we probably need is

WorkflowConsistencyChecker.WithWorkflowContextLock(
  context.Context, 
  Key, 
  func(context.Context, api.WorkflowContext) error,
  /* optional with defaults: Clock=nil, Predicate=Bypass, Prio=High */
)

Sure, someone could smuggle the api.WorkflowContext reference out of the func and up into the surrounding scope, but if you do that then at least it's more obvious that you're doing something wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this might actually be a good idea so I did #4337

@alexshtin alexshtin force-pushed the fix/ms-access-after-release branch from 4ec6fb7 to 75776b3 Compare May 15, 2023 21:20
@alexshtin alexshtin enabled auto-merge (squash) May 15, 2023 23:09
@alexshtin alexshtin merged commit 1240df2 into temporalio:master May 15, 2023
@alexshtin alexshtin deleted the fix/ms-access-after-release branch May 15, 2023 23:39
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.

2 participants