Repository navigation
v2.25.0
Minor release. A JetStream pull consumer can now be restarted with stop() (or drain()) and handle() in the same tick, without awaiting the run under way (#189). This is what a supervisor does when it changes a consumer's settings on a signal. Before, the second handle() cleared the stop meant for the earlier run. That run went on next to the new one, with its old handler and settings, until a later stop() reached it at its pull's deadline.
Upgrading is recommended if you restart a PullConsumerIterator without awaiting the previous handle() future. That includes restarting it from inside a handler, for example on a control message. Code that awaits each run before it starts the next sees no change. There are no API changes. What changes:
stop()anddrain()act on every run active when they are called, andhandle()no longer resets them. Eachhandle()run now has its own stop/drain flags and wake-ups.- After
stop()andhandle(), the earlier run ends on its stop, its future resolving with its count, and only the new run handles messages. Whatever the earlier run holds is left undelivered, as after anystop(). That holds in its retire phase and in every hand-over: a run that fails, one that goes on past a frame that ended the connection, the client'sdrain(), the overflow, and a terminal status. - After
drain()andhandle(), the earlier run delivers its pulls in flight to its own handler, next to the new run, and ends without pulling again. - Handlers can briefly overlap. The earlier run's handler may still be finishing its message when the new run starts. Await the earlier future first where two handlers must never run at once.
- Runs started without a
stop()in between still all go on, sharing a priority group's pin. Onestop()ends them all, now each at once; older runs used to see it only at their pull's deadline. Astop()ordrain()that an older run's handler makes once a newer run is going reaches the newer run too.
symfony-nats-messenger fetches with fetchBatch(), not the pull consumer iterator, so this release does not change it.
Changed
-
stop()ordrain()followed byhandle()in one tick restarts a pull consumer (#189). Measured on nats-server 2.12.15 with a durable consumer and explicit acks. A run of batch 1, depth 1 and a 30 s expiry waited on the empty stream; then camestop()andhandle()in one tick, and four published messages.- With 2.24.6, the first run's future was still pending 3 s later, and the old handler got m-1 and m-3 while the new one got m-2 and m-4. After a final
stop()the first run's pull still waited on the server. - With 2.25.0, the first run returns 0 at once, the server drops its request along with the interest in its inbox, and the new handler gets all four.
The 2.17.0 advice to await a run's future before calling
handle()again is withdrawn. - With 2.24.6, the first run's future was still pending 3 s later, and the old handler got m-1 and m-3 while the new one got m-2 and m-4. After a final
New example
examples/pull-consumer-restart.phprestarts a waiting pull consumer withstop()andhandle()in one tick, with a new batch size, then publishes three orders. It printsOK pull-consumer-restart: the stopped run handled 0 message(s), the restarted run all 3. Against 2.24.6 it fails withexpected the stopped run to end at its stop, it is still running.
Quality gates
- PHPStan level 8.
- 3265 unit tests (with data sets) on PHP 8.2 to 8.5, 153 live integration tests and 49 Behat scenarios.
- All 47 runnable examples executed against a live server, the new one included.
- Statement coverage: 98.88% from the unit suite (95% floor enforced in CI) and 98.93% combined (97% floor).
- Infection: covered MSI 93.03% over the 3818 mutants it ran (90% floor enforced in CI). It skipped 4778 of the 8596 it generated as too slow, so the score does not include them.
- Every change has tests that fail on the old code. There are 17 new test cases, decided by the order of events: 16 added, plus 1 replacing the test that pinned the lost stop. 14 of them fail on 2.24.6. The registry check errors there, since 2.24.6 has no registry. The other 2 are guards that pin what must not change: an await given up and a signal outside a run. The live integration test, the new Behat scenario and the new example fail on 2.24.6 too.
- Diff-mode Infection on the changed lines, with a 240 s budget per mutant so that nothing was skipped: 21 mutants, all killed. Ten hand-made mutants of the design were also all caught: no-op signals, a flag left unset, a missing wake-up, a run never registered or never removed, the engine's future returned, and a run registered before the names are validated.
The full record is in the CHANGELOG.