Skip to content

Commit

Permalink
producer: handle case of no transactions in popTransaction()
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ploxiln committed Aug 1, 2022
1 parent 827b836 commit 0056705
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0056705

Please sign in to comment.