Skip to content

Commit

Permalink
js: remove check of requests pending
Browse files Browse the repository at this point in the history
Skip 408 errors thrown to client no wait + expires requests

Signed-off-by: Waldemar Quevedo <wally@nats.io>
  • Loading branch information
wallyqs committed May 3, 2022
1 parent 9ac02cb commit 9ee663f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
13 changes: 6 additions & 7 deletions js.go
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion nats.go
Expand Up @@ -3317,7 +3317,6 @@ const (
noResponders = "503"
noMessagesSts = "404"
reqTimeoutSts = "408"
reqPendingDesc = "Requests Pending"
controlMsg = "100"
statusLen = 3 // e.g. 20x, 40x, 50x
)
Expand Down

0 comments on commit 9ee663f

Please sign in to comment.