// to finish the discussion that inadvertently became private
Big thanks to Josh and Jehiah for suggestions on fixing my race. In summary, for future reference: to get a clean shutdown without loosing a message to the shutting-down Consumer, either:
a) call Consumer.Stop() before doing message.Finish(); this seems to be the designed-in way to solve the shutdown race; or
b) SetMaxInFlight(0) before doing message.Finish().
Thanks again guys!
On Wed, Sep 30, 2015 at 11:33 AM, josh wrote:
Well, just for fun, I updated the gist. Now the handler gets a
reference to it's consumer, and calls Stop on it right before it calls
m.Finish(). It seems to, uh, work, I think, maybe.
Hi Josh, Thanks for pointing out Consumer.Stop(); it looks like it sends StartClose(), which according to the doc comment, is designed to handle my shutdown scenario. I tested it as an alternative to setting MaxInFlight to 0 before Finish(), and it does appear to work just fine to solve my race; my callee only gets one message.
// StartClose creates a new Command to indicate that the
// client would like to start a close cycle. nsqd will no longer
// send messages to a client in this state and the client is expected
// finish pending messages and close the connection
func StartClose() *Command {
return &Command{[]byte("CLS"), nil, nil}
}