Skip to content

Commit

Permalink
Merge pull request #618 from nats-io/ackbug
Browse files Browse the repository at this point in the history
Trying to ack a non JS msg would panic and hang
  • Loading branch information
derekcollison committed Dec 8, 2020
2 parents 55cabbc + 4dd05a8 commit d11d578
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions js.go
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,10 @@ func (m *Msg) checkReply() (*js, bool, error) {
}
sub := m.Sub
sub.mu.Lock()
if sub.jsi == nil {
sub.mu.Unlock()
return nil, false, ErrNotJSMessage
}
js := sub.jsi.js
isPullMode := sub.jsi.pull > 0
sub.mu.Unlock()
Expand Down
21 changes: 21 additions & 0 deletions test/js_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,27 @@ func TestJetStreamSubscribe(t *testing.T) {
}
}

func TestAckForNonJetStream(t *testing.T) {
s := RunBasicJetStreamServer()
defer s.Shutdown()

nc, err := nats.Connect(s.ClientURL())
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
defer nc.Close()

sub, _ := nc.SubscribeSync("foo")
nc.PublishRequest("foo", "_INBOX_", []byte("OK"))
m, err := sub.NextMsg(time.Second)
if err != nil {
t.Fatalf("Unexpected error: %v", err)
}
if err := m.Ack(); err != nats.ErrNotJSMessage {
t.Fatalf("Expected an error of '%v', got '%v'", nats.ErrNotJSMessage, err)
}
}

// TODO(dlc) - fill out with more stuff.
func TestJetStreamManagement(t *testing.T) {
s := RunBasicJetStreamServer()
Expand Down

0 comments on commit d11d578

Please sign in to comment.