Skip to content

Commit

Permalink
nsqd: SUB: fix ephemeral channel race condition with reconnecting cli…
Browse files Browse the repository at this point in the history
…ent.

It's possible for a client reconnecting quickly and subscribed to an ephemeral channel to race with nsqd's cleanup of said ephemeral channel, as documented in nsqio/go-nsq#206.

Fixes nsqio#883
  • Loading branch information
lilinzhe committed May 2, 2017
1 parent 71734e9 commit 0eb302c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions nsqd/protocol_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,15 @@ func (p *protocolV2) SUB(client *clientV2, params [][]byte) ([]byte, error) {
}

topic := p.ctx.nsqd.GetTopic(topicName)
for topic.Exiting() {
time.Sleep(1 * time.Microsecond)
topic = p.ctx.nsqd.GetTopic(topicName)
}
channel := topic.GetChannel(channelName)
for channel.Exiting() {
time.Sleep(1 * time.Microsecond)
channel = topic.GetChannel(channelName)
}
channel.AddClient(client.ID, client)

atomic.StoreInt32(&client.State, stateSubscribed)
Expand Down

0 comments on commit 0eb302c

Please sign in to comment.