-
-
Notifications
You must be signed in to change notification settings - Fork 532
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
[client] Fix state manager race conditions #2890
Conversation
start := time.Now() | ||
go func() { | ||
done <- util.WriteJsonWithRestrictedPermission(ctx, m.filePath, m.states) | ||
done <- util.WriteBytesWithRestrictedPermission(ctx, m.filePath, bs) |
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.
What will be if this function running more then 10 sec? The ticker will start a PersistState call and will be a conflict in the file.
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.
That's what the ctx check and deadline is for in this fn
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.
But the check and move is not an atomic operation. If the code runs parallel this lines with two different ctx the outcome is unpredictable.
// Check context again
if ctx.Err() != nil {
return ctx.Err()
}
if err = os.Rename(tempFileName, file); err != nil {
return fmt.Errorf("move %s to %s: %w", tempFileName, file, err)
}
```
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.
Lets do it in separated PR
9f68e34
to
c8ec1bc
Compare
Quality Gate passedIssues Measures |
Describe your changes
Issue ticket number and link
Checklist