Skip to content

Commit

Permalink
Merge 405da00 into ea036d7
Browse files Browse the repository at this point in the history
  • Loading branch information
wallyqs committed May 3, 2021
2 parents ea036d7 + 405da00 commit 4f8d13f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nats.go
Expand Up @@ -3932,7 +3932,8 @@ func (jsi *jsSub) trackSequences(msg *Msg) {

// NextMsg will return the next message available to a synchronous subscriber
// or block until one is available. An error is returned if the subscription is invalid (ErrBadSubscription),
// the connection is closed (ErrConnectionClosed), or the timeout is reached (ErrTimeout).
// the connection is closed (ErrConnectionClosed), the timeout is reached (ErrTimeout),
// or if there were no responders (ErrNoResponders) when used in the context of a request/reply.
func (s *Subscription) NextMsg(timeout time.Duration) (*Msg, error) {
if s == nil {
return nil, ErrBadSubscription
Expand Down Expand Up @@ -4053,6 +4054,9 @@ func (s *Subscription) processNextMsgDelivered(msg *Msg) error {
nc.mu.Unlock()
}
}
if len(msg.Data) == 0 && msg.Header.Get(statusHdr) == noResponders {
return ErrNoResponders
}

return nil
}
Expand Down
14 changes: 14 additions & 0 deletions test/basic_test.go
Expand Up @@ -623,6 +623,20 @@ func TestBasicNoRespondersSupport(t *testing.T) {
if m, err := nc.RequestWithContext(ctx, "foo", nil); err != nats.ErrNoResponders {
t.Fatalf("Expected a no responders error and nil msg, got m:%+v and err: %v", m, err)
}

// SubscribeSync
inbox := nats.NewInbox()
sub, err := nc.SubscribeSync(inbox)
if err != nil {
t.Fatal(err)
}
err = nc.PublishRequest("foo", inbox, nil)
if err != nil {
t.Fatal(err)
}
if m, err := sub.NextMsg(2 * time.Second); err != nats.ErrNoResponders {
t.Fatalf("Expected a no responders error and nil msg, got m:%+v and err: %v", m, err)
}
}

func TestOldRequest(t *testing.T) {
Expand Down

0 comments on commit 4f8d13f

Please sign in to comment.