From 0eb302cca201478d5c60afeba89d75e154e600a1 Mon Sep 17 00:00:00 2001 From: lilinzhe Date: Tue, 2 May 2017 05:09:49 +0000 Subject: [PATCH] nsqd: SUB: fix ephemeral channel race condition with reconnecting client. 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 #883 --- nsqd/protocol_v2.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nsqd/protocol_v2.go b/nsqd/protocol_v2.go index 02ba0dac3..89e167506 100644 --- a/nsqd/protocol_v2.go +++ b/nsqd/protocol_v2.go @@ -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)