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

[FIXED] RACE in Sublist #641

Merged
merged 3 commits into from
Mar 15, 2018
Merged

[FIXED] RACE in Sublist #641

merged 3 commits into from
Mar 15, 2018

Conversation

kozlovic
Copy link
Member

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

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
@kozlovic kozlovic requested a review from derekcollison March 10, 2018 02:08
@kozlovic
Copy link
Member Author

@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.

@coveralls
Copy link

coveralls commented Mar 10, 2018

Coverage Status

Coverage decreased (-0.02%) to 92.067% when pulling 3bfb2d7 on fix_sublist_race into dd3dccc on master.

@kozlovic kozlovic self-assigned this Mar 10, 2018
@kozlovic kozlovic added the bug label Mar 10, 2018
// 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)
Copy link
Member

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.

Copy link
Member Author

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.
Copy link
Member

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" {
Copy link
Member

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?

Copy link
Member Author

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.
results.qsubs = append(results.qsubs, qr)
copyqr := make([]*subscription, len(qr))
copy(copyqr, qr)
results.qsubs = append(results.qsubs, copyqr)
Copy link
Member

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().
@kozlovic kozlovic changed the title [FIXED] RACE between sublist remove and go through match results [FIXED] RACE in Sublist Mar 15, 2018
@kozlovic kozlovic merged commit 982643a into master Mar 15, 2018
@kozlovic kozlovic deleted the fix_sublist_race branch March 15, 2018 21:48
@bruth bruth removed the 🐞 bug label Aug 18, 2023
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.

4 participants