diff --git a/nsqd/protocol_v2.go b/nsqd/protocol_v2.go index ccf0f7223..f89d7aef1 100644 --- a/nsqd/protocol_v2.go +++ b/nsqd/protocol_v2.go @@ -70,8 +70,8 @@ func (p *ProtocolV2) IOLoop(conn net.Conn) error { } log.Printf("ERROR: [%s] - %s%s", client, err.Error(), context) - err = p.Send(client, nsq.FrameTypeError, []byte(err.Error())) - if err != nil { + sendErr := p.Send(client, nsq.FrameTypeError, []byte(err.Error())); + if sendErr != nil { break } diff --git a/nsqd/protocol_v2_test.go b/nsqd/protocol_v2_test.go index 4cc80f98a..f4d3ea6e9 100644 --- a/nsqd/protocol_v2_test.go +++ b/nsqd/protocol_v2_test.go @@ -587,6 +587,29 @@ func TestMaxRdyCount(t *testing.T) { assert.Equal(t, string(data), "E_INVALID RDY count 51 out of range 0-50") } +func TestFatalError(t *testing.T) { + log.SetOutput(ioutil.Discard) + defer log.SetOutput(os.Stdout) + + tcpAddr, _ := mustStartNSQd(NewNsqdOptions()) + defer nsqd.Exit() + + conn, err := mustConnectNSQd(tcpAddr) + assert.Equal(t, err, nil) + + _, err = conn.Write([]byte("ASDF\n")) + assert.Equal(t, err, nil) + + resp, err := nsq.ReadResponse(conn) + assert.Equal(t, err, nil) + frameType, data, err := nsq.UnpackResponse(resp) + assert.Equal(t, frameType, int32(1)) + assert.Equal(t, string(data), "E_INVALID invalid command ASDF") + + _, err = nsq.ReadResponse(conn) + assert.NotEqual(t, err, nil) +} + func BenchmarkProtocolV2Exec(b *testing.B) { b.StopTimer() log.SetOutput(ioutil.Discard)