nsqio / go-nsq

The official Go package for NSQ
MIT License
2.59k stars 444 forks source link

conn: possible deadlock caused by readLoop #263

Closed CxdInitial closed 4 years ago

CxdInitial commented 5 years ago

If the read in readLoop failed (error occurs), when exiting messagesInFlight is positive, readLoop do nothing. closeFlag is zero. https://github.com/nsqio/go-nsq/blob/61f49c096d0d767be61e4de06f724e1cb5fd85d7/conn.go#L543-L552

But what if the write in writeLoop just works (no error), and eventually it will block forever . The logic below won't be executed. https://github.com/nsqio/go-nsq/blob/61f49c096d0d767be61e4de06f724e1cb5fd85d7/conn.go#L595-L599 https://github.com/nsqio/go-nsq/blob/61f49c096d0d767be61e4de06f724e1cb5fd85d7/conn.go#L588-L593 https://github.com/nsqio/go-nsq/blob/61f49c096d0d767be61e4de06f724e1cb5fd85d7/conn.go#L564-L569

mreiferson commented 4 years ago

go-nsq expects that a consumer will "finish" all messages in flight, eventually, in order to close cleanly.

The edge case you describe is effectively a consumer that does not respond to all of its in-flight messages.