Skip to content

v2.25.1

Choose a tag to compare

@bpacholek bpacholek released this 10 Oct 14:30
· 102 commits to main since this release

Patch release. A pull consumer whose reply inbox the server rejects while its handler runs no longer pulls again on the dead inbox; it fails with the rejection at once (#206).

Upgrading is recommended for pull consumers whose subscribe permissions can change at runtime (configuration reloads), and for accounts close to their subscription limit. It matters most on servers with leaf nodes or gateways, where such a pull could lose messages. There are no API changes; the new pieces are internal.

Fixed

  • No further pull on a rejected inbox (#206). nats-server rejects a pull consumer's reply inbox mid-run in two cases. A configuration reload that withdraws the subscribe permission sends Permissions Violation for Subscription to "_INBOX.JS.PULL.<nuid>.*", leaving the connection open. A reconnect's replay of the inbox is refused when the new server is at the account's subscription limit. Whichever fiber's read met the -ERR recorded the rejection: your handler's own processIncoming(), an application's read loop while the handler or onError waited, or a failed write's recovery. The run only looked at it at the top of its loop. So the pass went on to refill the pipeline on the dead inbox and to wait for the new pull's deadline, setExpiresMs() plus a second, or for unrelated bytes to arrive. A finite run with no pull left returned its count without the error. A later pull's terminal status ended the run as if nothing had happened. The idle backoff was not woken. A pull whose write failed was retried after its recovery's replay had been rejected.

    Those pulls were not harmless. With leaf nodes or gateways enabled, nats-server serves a pull younger than 2 s even when its reply subject has no local interest, so the batch went to an inbox nobody held. On a consumer with ack_policy: none or max_deliver: 1 it was lost; otherwise it came again only after ack_wait.

    The run now looks at the rejection after every wait that can let another fiber run. The rejection also wakes the run's read and its idle backoff at once, and each pull is published through a guard that refuses it once the rejection is recorded, before a retry after recovery too. No new pull and no retry goes out once the run knows its inbox was rejected. The run still hands what its pulls hold to your handler first, as before any failure (#197), and then throws the rejection.

    Measured on nats-server 2.12.15 with leafnodes { port: 7422 } and a consumer with ack_policy: none holding three messages. A configuration reload withdrew the permission while the handler held m-1, and another fiber read the -ERR. With 2.25.0, a pull went out right after the rejection and the server served m-2 to nobody (num_pending 1, delivered.stream_seq 2). handle() failed only when the server's next PING ended its read, about 2 s later; without that PING it would have waited for the pull's deadline. With 2.25.1, handle() throws the rejection within a millisecond, the only write after it is the inbox's UNSUB, and m-2 and m-3 stay on the consumer (num_pending 2, 5/5 runs).

Before upgrading

  • A finite run (setIterations()) that has delivered its last batch now throws the rejection instead of returning its count when the inbox was rejected during the run. So does a run that a later pull's terminal status, such as 409 Consumer Deleted, would have ended; that status then never reaches onError.
  • A stop() made by then still makes handle() return its count, and a handler or onError that throws still ends the run with its own exception.
  • A pull that the socket had already taken, or that was already in the reconnect buffer, can still go out. The fix stops new pulls and retries; it does not recall those.

Quality gates

  • PHPStan level 8.
  • 3304 unit tests (with data sets) on PHP 8.2 to 8.5, 153 live integration tests and 49 Behat scenarios. All 47 runnable examples pass.
  • Statement coverage 98.90% from the unit suite (95% floor enforced in CI) and 98.95% combined (97% floor). Every changed line is covered (codecov/patch 100%).
  • Infection covered MSI 93.30% over the 3656 mutants it ran (90% floor enforced in CI). It skipped 4968 of the 8624 it generated as too slow, so the score does not include them.
  • 39 new unit cases. 21 of the 26 engine cases fail on 2.25.0, and the 5 declared guards pass on both. 15 hand-made mutants, each removing one check, wake-up or guard call, are all killed.
  • On the changed lines, with a 240 s per-mutant budget: 48 mutants. 36 were killed, and 6 timed out and 1 errored, which also count as killed. The one escape is equivalent. The 4 skipped as too slow were killed by hand.

The full record is in the CHANGELOG.