-
Notifications
You must be signed in to change notification settings - Fork 311
Block Sends when Resend Request is active #715
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
Changes from all commits
c527fc8
4d324d5
bbefdb7
1607e8b
e954566
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,9 @@ type session struct { | |
|
||
// Mutex for access to toSend. | ||
sendMutex sync.Mutex | ||
// Mutex to prevent messages being sent when resendRequest is active | ||
// Must be locked before sendMutex to prevent a potential deadlock | ||
resendMutex sync.RWMutex | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Additional comment above this as well indicating the reason why this mutex exists in conjunction with the sendMutex and in which order they must be locked to avoid deadlocks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
sessionEvent chan internal.Event | ||
messageEvent chan bool | ||
|
@@ -302,6 +305,10 @@ func (s *session) sendInReplyTo(msg *Message, inReplyTo *Message) error { | |
return s.queueForSend(msg) | ||
} | ||
|
||
// resendMutex must always be locked before sendMutex to prevent a potential deadlock | ||
s.resendMutex.RLock() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mirror other comment here as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
defer s.resendMutex.RUnlock() | ||
|
||
s.sendMutex.Lock() | ||
defer s.sendMutex.Unlock() | ||
|
||
|
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.
Please place a comment indicating that this lock must always be locked first before the sendMutex, otherwise there is potential for a deadlock, and that mutex is locked within the
session.EnqueueBytesAndSend
method belowThere 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.
e954566