From 00567053fbb870b32790334c2fe68a32aaf4a3b2 Mon Sep 17 00:00:00 2001 From: Pierce Lopez Date: Sun, 5 Jun 2022 17:33:43 -0400 Subject: [PATCH] producer: handle case of no transactions in popTransaction() This corner case generally should not happen, but a nsqd bug or strange network condition could possibly send erroneous bytes that are interpreted as a response. The Producer should be robust, and not panic the whole process. --- producer.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/producer.go b/producer.go index 20fd0c87..853714f4 100644 --- a/producer.go +++ b/producer.go @@ -367,6 +367,17 @@ exit: } func (w *Producer) popTransaction(frameType int32, data []byte) { + if len(w.transactions) == 0 { + dataLen := len(data) + if dataLen > 32 { + data = data[:32] + } + w.log(LogLevelError, + "(%s) unexpected response type=%d len=%d data[:32]=0x%x", + w.conn.String(), frameType, dataLen, data) + w.close() + return + } t := w.transactions[0] w.transactions = w.transactions[1:] if frameType == FrameTypeError {