-
Notifications
You must be signed in to change notification settings - Fork 387
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
storagenode/orders: fix data race in settle #3042
Conversation
@@ -291,7 +290,7 @@ func (service *Service) settle(ctx context.Context, log *zap.Logger, satelliteID | |||
zap.Error(err), | |||
zap.Any("request", req), | |||
) | |||
errList.Add(err) | |||
sendErrors.Add(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.
Couldn't we use a buffered of error
elements channel of len(orders)
capacity and iterate over it after group.Wait()
excluding nil
element and accumulate them errList
how it's done now?
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.
Why? This sounds like a much more complicated approach than it's currently using.
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.
isn't sendErrors.Add
called concurrently? of if it's .Add
is safe to be called concurrently?
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.
sendErrors.Add
is not called concurrently
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.
oh yeah, I saw the loop and the group in inverse order.
I've got confused with the "unfortunately" part of the initial message.
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'm confused now. why is sendErrors.Add
not called concurrently?
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.
There is only goroutine using sendErrors
at a time at all times. I.e. it's called from another goroutine
, but there's only one of those.... so technically no concurrent calls.
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.
Because it's only called inside of group.Go
and it's read after the group ends.
I was mistaken because my brain lied to me making me see the for loop
before group.Go
so I thought that several goroutines created by several calls to group.Go
were running, but the loop it's inside so there is only one goroutine.
@@ -291,7 +290,7 @@ func (service *Service) settle(ctx context.Context, log *zap.Logger, satelliteID | |||
zap.Error(err), | |||
zap.Any("request", req), | |||
) | |||
errList.Add(err) | |||
sendErrors.Add(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.
oh yeah, I saw the loop and the group in inverse order.
I've got confused with the "unfortunately" part of the initial message.
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.
LGTM
errList
was being modified from two goroutines, use a separate errs.Group to capture errors. Unfortunately,errs.Group
cannot be returned easily fromgroup.Go
, which would allow to make this bug less likely.Please describe the tests:
Please describe the performance impact:
Code Review Checklist (to be filled out by reviewer)