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

message: atomic races #120

Merged
merged 1 commit into from
Feb 21, 2015
Merged
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
6 changes: 2 additions & 4 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ func (m *Message) HasResponded() bool {
// Finish sends a FIN command to the nsqd which
// sent this message
func (m *Message) Finish() {
if m.HasResponded() {
if !atomic.CompareAndSwapInt32(&m.responded, 0, 1) {
return
}
m.Delegate.OnFinish(m)
atomic.StoreInt32(&m.responded, 1)
}

// Touch sends a TOUCH command to the nsqd which
Expand Down Expand Up @@ -101,11 +100,10 @@ func (m *Message) RequeueWithoutBackoff(delay time.Duration) {
}

func (m *Message) doRequeue(delay time.Duration, backoff bool) {
if m.HasResponded() {
if !atomic.CompareAndSwapInt32(&m.responded, 0, 1) {
return
}
m.Delegate.OnRequeue(m, delay, backoff)
atomic.StoreInt32(&m.responded, 1)
}

// WriteTo implements the WriterTo interface and serializes
Expand Down