-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[FIXED] RACE in Sublist #641
Conversation
This would manifest for instance when server tries to send messages to queue subscribers and a subscription is unsubsribed at the same time. Resolves #640
@derekcollison Not sure if this the only way to fix, but clearly there was an issue between the results from a match and a subscription being removed from the sublist. |
server/sublist.go
Outdated
// Store in cache and return to caller a copy of the results to avoid | ||
// race when sub is removed from sublist and caller walks through the | ||
// results. | ||
cr := copyResult(result) |
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.
This feels like it could be a performance hit for sure.
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 revised to just copy where needed (in matchLevel)
@@ -1,3 +1,6 @@ | |||
// Copyright 2012-2017 Apcera Inc. All rights reserved. | |||
// Copyright 2018 Synadia Communications Inc. All rights reserved. |
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 will change all of these at some point next week.
for _, qsub := range r.qsubs { | ||
for i := 0; i < len(qsub); i++ { | ||
sub := qsub[i] | ||
if string(sub.queue) != "bar" { |
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.
Should we rewrite it above to make it deterministic?
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.
Not sure what you mean here?
…ults Instead of making a copy of the whole results, make sure that we don't pass a sublist array to the result but its copy.
server/sublist.go
Outdated
results.qsubs = append(results.qsubs, qr) | ||
copyqr := make([]*subscription, len(qr)) | ||
copy(copyqr, qr) | ||
results.qsubs = append(results.qsubs, copyqr) |
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.
Any noticeable performance hit? Any other way to avoid the allocation and copy even of the array?
Use the append([]*subscription(nil), qr...) notation instead of make()+copy().
This would manifest for instance when server tries to send messages
to queue subscribers and a subscription is unsubsribed at the same
time.
Resolves #640