Skip to content

v2.27.1

Choose a tag to compare

@bpacholek bpacholek released this 17 Oct 16:14
· 38 commits to main since this release

Patch release, with upgrade notes: read "Before upgrading".

Fixed

A plain publish whose write is the first to notice a lost connection no longer waits for the reconnect (#244).

Up to now such a publish ran the whole reconnect loop in the caller's fiber, with no budget or cancellation, and wrote the frame again once the loop was over. At the default policy (10 attempts, 100 ms doubling to 10 s) that is about 100 s for a server that does not come back. A second publisher whose write failed meanwhile joined the same wait. Through the Symfony Messenger transport, a plain ack() that met an outage returned after 103 s, while one issued a moment later, once the heartbeat had noticed, returned in under a millisecond.

The frame now goes to the reconnect buffer, as a publish made during a reconnect always did, and the publish resolves once the frame is accepted there. The reconnect runs on its own and flushes the frame after the subscription replay. This covers publish(), publishWithHeaders(), a JetStream ack(), nak(), term() and inProgress(), respond(), service replies, and the intermediates of an atomic batch.

  • The frame is accepted before any lifecycle callback. It is decided as the reconnect leaves Open, so a Disconnected listener can neither take its room in the buffer nor close the connection first.
  • A drain that waits for the reconnect finds the frame sent. A slow Reconnected listener used to let such a drain close the connection before the publish's retry.

Who should upgrade: anyone who publishes or acks fire-and-forget with reconnect on. A worker whose ack met a dead socket was stuck for the whole reconnect.

Before upgrading

  • The publish resolves early. It resolves once its frame is buffered, not once it is written. If the reconnect gives up or fails authentication, the loss is reported through the errorListener (Reconnect exhausted: N bytes of buffered publishes were discarded) and the Closed event, not through the publish. It used to fail with Reconnect attempts exhausted. A resolved ack() never meant the server recorded it: use ackSync() for that.
  • The buffer's limits apply. With reconnectBufferSize: 0, or a full buffer, the publish fails at once with Connection is not open, the write's error as its previous one, and the reconnect goes on.
  • disconnect() stays lossy. A disconnect() during the reconnect discards the accepted frame without a report, as it discards every buffered publish. A write that fails after you closed and reopened the connection now fails the publish, instead of being written to the new connection.
  • The order across publishers changes. Frames are flushed in the order they were accepted. The failed frame can now go out ahead of frames other fibers buffered after it. One publisher's frames keep their order.
  • A frame that always fails exhausts the reconnect. Like any buffered frame, it fails every flush. A failed flush write is retried, so a frame may arrive twice. With the built-in transports a write error belongs to the socket, not to the frame.
  • Two waits remain. The original write itself, and a sealed flush under sustained publishing (#165).
  • Code that relied on the wait must wait itself. Call flush() after the publish. It waits for the reconnect within requestTimeoutMs when waitForReconnect is on.
  • Unchanged:
    • publishGuarded(), the pull consumer engine's publish, keeps its inline recovery.
    • With reconnect off, a failed write still fails with Reconnect is disabled.
    • Requests, ackSync() and JetStream publishes keep their bounded request path.
    • There are no API changes.

Quality gates

  • PHPStan level 8.
  • 3701 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: every modified coverable line is covered. Total coverage 98.98%.
  • Infection covered MSI 92.99% on main (90% floor enforced in CI). It skipped 4740 of the 8937 mutants it generated as too slow, so the score does not include them. In the changed lines, a diff-mode run left no mutant escaped (25 killed, 3 timed out, 53 skipped as too slow).
  • New FailedPublishWriteTest, 41 cases over the scripted reconnecting server, plus a live test: a plain ack() whose write meets a severed socket resolves while dials are refused, and the server records it once the connection is back. The six comparison cases from the issue's review pass against the implementation.
  • The PR's push-run Mutation job first failed on a known wall-clock flake unrelated to this change (OperationTakesItsQueuedMessageTest, a 0.5 s bound measured at 0.518 s under coverage in random order). That test passes in isolation under coverage, and the rerun, the PR run and main's run passed.

The full record is in the CHANGELOG.