diff --git a/js.go b/js.go index d9522235a..4013a975e 100644 --- a/js.go +++ b/js.go @@ -2427,7 +2427,7 @@ var ( // Returns if the given message is a user message or not, and if // `checkSts` is true, returns appropriate error based on the // content of the status (404, etc..) -func checkMsg(msg *Msg, checkSts bool) (usrMsg bool, err error) { +func checkMsg(msg *Msg, checkSts, isNoWait bool) (usrMsg bool, err error) { // Assume user message usrMsg = true @@ -2457,9 +2457,8 @@ func checkMsg(msg *Msg, checkSts bool) (usrMsg bool, err error) { err = errNoMessages case reqTimeoutSts: // In case of a fetch request with no wait request and expires time, - // it will be a 408 error but with a Requests Pending description. - desc := msg.Header.Get(descrHdr) - if desc == reqPendingDesc { + // need to skip 408 errors and retry. + if isNoWait { err = errRequestsPending } else { // Older servers may send a 408 when a request in the server was expired @@ -2582,7 +2581,7 @@ func (sub *Subscription) Fetch(batch int, opts ...PullOpt) ([]*Msg, error) { // or status message, however, we don't care about values of status // messages at this point in the Fetch() call, so checkMsg can't // return an error. - if usrMsg, _ := checkMsg(msg, false); usrMsg { + if usrMsg, _ := checkMsg(msg, false, false); usrMsg { msgs = append(msgs, msg) } } @@ -2625,11 +2624,11 @@ func (sub *Subscription) Fetch(batch int, opts ...PullOpt) ([]*Msg, error) { if err == nil { var usrMsg bool - usrMsg, err = checkMsg(msg, true) + usrMsg, err = checkMsg(msg, true, noWait) if err == nil && usrMsg { msgs = append(msgs, msg) } else if noWait && (err == errNoMessages || err == errRequestsPending) && len(msgs) == 0 { - // If we have a 404 for our "no_wait" request and have + // If we have a 404/408 for our "no_wait" request and have // not collected any message, then resend request to // wait this time. noWait = false diff --git a/nats.go b/nats.go index 952329de6..81332aed9 100644 --- a/nats.go +++ b/nats.go @@ -3317,7 +3317,6 @@ const ( noResponders = "503" noMessagesSts = "404" reqTimeoutSts = "408" - reqPendingDesc = "Requests Pending" controlMsg = "100" statusLen = 3 // e.g. 20x, 40x, 50x )