Skip to content

Commit

Permalink
Merge pull request #198 from mreiferson/fatal_error_fix_198
Browse files Browse the repository at this point in the history
nsqd: fatal errors are not fatal
  • Loading branch information
jehiah committed May 13, 2013
2 parents 8c3caeb + 7a2abe2 commit 178e369
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions nsqd/protocol_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
23 changes: 23 additions & 0 deletions nsqd/protocol_v2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 178e369

Please sign in to comment.