Skip to content

v2.23.0

Choose a tag to compare

@bpacholek bpacholek released this 09 Oct 01:31
· 131 commits to main since this release

Minor release. An infinite JetStream pull consumer run, PullConsumerIterator::handle() without setIterations(), now goes on after the server ends the connection with a fatal -ERR such as Stale Connection or User Authentication Expired, once the reconnect has reopened it, as it already went on after a lost connection (#210). Before, handle() threw the server's error while the connection was open again, and a worker stopped consuming until something started it again.

Upgrading is recommended if you run long-lived pull consumers with reconnect on: workers whose handlers sometimes block the event loop for longer than a few of the server's ping intervals (the server then sends Stale Connection), and consumers using short-lived JWTs that jwtProvider renews on every reconnect (each expiry sent User Authentication Expired). There are no API changes. What changes for an infinite run with reconnect on and waitForReconnect enabled (the defaults):

  • The server's error goes to the errorListener and to the logger (NATS connection error: Server sent error frame: 'Stale Connection') instead of out of handle().
  • What the run's pulls had received when the connection ended goes to the handler as part of the run, in the order it arrived, and counts in the result of handle(). A handler that throws there ends the run with its own exception.
  • The run then pulls again on the new connection.

A finite run still ends with the server's error, and so does an infinite run with reconnect off or waitForReconnect: false, or whose connection you are closing. An infinite run whose reconnect gives up ends as it does after a lost connection.

symfony-nats-messenger fetches with fetchBatch(), not the pull consumer iterator, and works with this release unchanged.

Fixed

  • An infinite pull consumer run ended on a fatal -ERR or a failed PONG even when the reconnect had reopened the connection (#210). The read that met such a frame recovered the connection and threw the frame's error once the reconnect was done, and the engine took that as the end of the run, where after an EOF it pulls again on the new connection. Such a run now goes on as after a lost connection. Measured on nats-server 2.12 with ping_interval: "1s" and ping_max: 1: an infinite run whose handler blocked the process for 3.5 s. With 2.22.0, handle() threw Server sent error frame: 'Stale Connection' right after the Reconnected event, and the messages published afterwards were never consumed. With 2.23.0 the error reaches the error listener, the run consumes those messages on the new connection, and nothing is left pending.

Quality gates

  • PHPStan level 8.
  • 3016 unit tests (with data sets) on PHP 8.2 to 8.5, 149 live integration tests and 48 Behat scenarios.
  • All 45 runnable examples executed against a live server.
  • Statement coverage 98.83% from the unit suite (95% floor enforced in CI) and 98.89% combined (97% floor).
  • Infection covered MSI 92.6% over the 3844 mutants it ran (90% floor enforced in CI); it skipped 4280 of the 8124 it generated as too slow, so the score does not include them.
  • Every change has tests that fail on the old code. 36 new test cases, decided by the order of events: 22 fail on 2.22.0, and the other 14 are controls (the same run after an EOF) and guards that pin what must not change. Six existing tests that used a fatal -ERR as the failure of an infinite run with reconnect on were moved to reconnect off (one to waitForReconnect: false), so they keep testing what they tested. On the changed lines, Infection generated 71 mutants: 34 killed, 4 timed out, 26 skipped as too slow and 7 escaped. Four of the escaped ones reset idle counters that the reconnect resets again, one changes a condition with no observable effect, and two only change whether a pull is issued during a slow reconnect, which is the open issue #187.
  • The change was reviewed for semantics and for interleavings by two independent reviewers, and their findings were applied.
  • symfony-nats-messenger's main branch against this release: PHPStan level max, 528 unit tests, 52 functional scenarios against live NATS and 5 examples pass.

The full record is in the CHANGELOG.