Skip to content

v2.27.2

Choose a tag to compare

@bpacholek bpacholek released this 17 Oct 22:22
· 35 commits to main since this release

Patch release.

Fixed

An infinite pull consumer run (pullConsumer()->handle()) now ends on a terminal pull status that arrives in the same read as a frame that ends the connection (#214).

Since 2.23.0 (#210), an infinite run outlives a fatal -ERR such as Stale Connection, or a PONG the socket would not take, once the reconnect has reopened the connection. It hands what its pulls held to your handler and goes on. A pull status read in the same chunk as that frame was dropped with the pulls, unread. That chunk is what a process blocked long enough to draw Stale Connection finds when the consumer is deleted meanwhile, because nats-server answers every waiting pull with 409 Consumer Deleted. The 409 never reached onError, and the run kept polling. On the deleted consumer each pull then got a 503, which the run treats as routine and reports once. So the application heard of a server outage, not of a deleted consumer, and the run never ended. The same 409 read on its own already ended the run.

Now each pull that brought no message is classified the way the retire phase classifies an empty pull, once every pull's messages have gone to the handler:

  • A terminal status ends the run as it does elsewhere. The inbox is closed first (#211), onError gets the status once, what the overflow holds goes to the handler, and handle() returns the count. Nothing is pulled on the new connection.
  • A 423 drops the pin that request sent (#208), and the group acquires its pin serially again.
  • A routine status (404, 408, 409 Leadership Change, 503), or none, changes nothing. The run pulls on as after an EOF.

Who should upgrade: anyone running infinite pull consumers on a server where consumers can be deleted while the process stalls, for example under a long garbage collection or a blocking call. There are no API changes.

Before upgrading

  • Such a run now ends. A run that used to poll on after a deleted consumer now returns its count from handle(), with the 409 delivered to onError once. Code that relied on the run going on must start it again, as it already did for a 409 read on its own.
  • A pull that brought messages keeps its status unclassified, as in the retire phase: its messages go to the handler, and the run goes on.
  • A 503 from the old connection isn't reported. The run is past that connection, so a routine status in the frame's chunk isn't sent to onError.

Quality gates

  • PHPStan level 8.
  • 3714 unit tests (with data sets) on PHP 8.2 to 8.5, 160 live integration tests and 49 Behat scenarios. All runnable examples pass.
  • codecov/patch 100%: every changed line is covered (47 of 47). Total coverage 99.05%.
  • Infection covered MSI 92.90% (90% floor enforced in CI). It skipped 4744 of the 8972 mutants it generated as too slow, so the score does not include them. That includes most mutants of the pull engine.
  • A local Infection run on the changed lines, with a 300 s budget so that none were skipped: 78 mutants, 68 killed (8 by an error and 1 by a time-out), 10 escaped. Six are equivalent. Four point at test gaps, not at wrong code: a terminal status behind another empty pull in the frame's chunk, and the readiness reset after a 423. They are tracked in #247.
  • New PullConsumerStatusInTheChunkOfAConnectionEndingFrameTest, 13 cases over a reconnecting scripted server. 7 of them fail on 2.27.1. The other 6 are guards that pass on both.
  • Eight broken variants of the fix were tried, and each fails at least one case.

The full record is in the CHANGELOG.