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

channel.go: avoid race condition by synchronizing ch.send calls #499

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ func (ch *Channel) open() error {
// Performs a request/response call for when the message is not NoWait and is
// specified as Synchronous.
func (ch *Channel) call(req message, res ...message) error {
ch.m.Lock()

Choose a reason for hiding this comment

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

Isn't there a lock implemented on the connection object c.sendM before writing to the frame. That should be doing the same thing, right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is indeed typically done at connection level by various clients. We have to be really careful here as throughput effects of locking on the hot path can be very serious or even catastrophic for some systems.

defer ch.m.Unlock()

if err := ch.send(req); err != nil {
return err
}
Expand Down Expand Up @@ -288,7 +291,9 @@ func (ch *Channel) dispatch(msg message) {
c <- m.Active
}
ch.notifyM.RUnlock()
ch.m.Lock()
ch.send(&channelFlowOk{Active: m.Active})
ch.m.Unlock()

case *basicCancel:
ch.notifyM.RLock()
Expand Down