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] Possible race causing ack'ed message to be redelivered #1139

Merged
merged 2 commits into from Jan 8, 2021

Conversation

kozlovic
Copy link
Member

@kozlovic kozlovic commented Jan 8, 2021

During redelivery, a go routine gathers all pending messages under
a lock. However, the actual send of messages is done one by one
and by then, one of the message in the list of messages to redeliver
may have been acknowledged. So during the send, under the sub's lock,
we need to check that if a message marked as redelivered is no longer
in the pending list, it should not be sent to the client.

Also fixed an unrelated data race that was just found running tests.

Resolves #1138

Signed-off-by: Ivan Kozlovic ivan@synadia.com

During redelivery, a go routine gathers all pending messages under
a lock. However, the actual send of messages is done one by one
and by then, one of the message in the list of messages to redeliver
may have been acknowledged. So during the send, under the sub's lock,
we need to check that if a message marked as redelivered is no longer
in the pending list, it should not be sent to the client.

Also fixed an unrelated data race that was just found running tests.

Resolves #1138

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
@coveralls
Copy link

coveralls commented Jan 8, 2021

Coverage Status

Coverage increased (+0.07%) to 91.76% when pulling d6cf6e3 on fix_1138 into 564e335 on master.

server/server.go Outdated
@@ -3721,23 +3730,28 @@ func (s *StanServer) performAckExpirationRedelivery(sub *subState, isStartup boo
// otherwise this could cause a message to be redelivered to multiple members.
if !isClustered && qs != nil && !isStartup {
qs.Lock()
sub.Lock()
skip := !sub.isMsgStillPending(m)
Copy link
Member

Choose a reason for hiding this comment

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

very minor nitpick, take it or leave it, but could use msgPending := sub.isMsgStillPending(m) and avoid the !s. It might read easier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will do, and actually should not try to send if not pending.. so thanks!

Copy link
Member

@ColinSullivan1 ColinSullivan1 left a comment

Choose a reason for hiding this comment

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

LGTM.

Used code review recommendation and fixed the queue case. Added
queue sub in new test that would have caught the bug.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
Copy link
Member

@ColinSullivan1 ColinSullivan1 left a comment

Choose a reason for hiding this comment

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

LGTM.

@kozlovic kozlovic merged commit 71d1dbc into master Jan 8, 2021
@kozlovic kozlovic deleted the fix_1138 branch January 8, 2021 18:22
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.

Server may redeliver a message that has just been acknoweldged
3 participants