Skip to content

v2.0.0 — hardening + official Object Store interop

Choose a tag to compare

@bpacholek bpacholek released this 07 Jun 15:44
· 507 commits to main since this release

Major release. Broad correctness, robustness, security, and performance hardening across the
connection, JetStream, KeyValue, ObjectStore, and microservices layers — plus the rewrite of
Object Store to the official NATS layout for cross-client interoperability.

Every change ships with tests. The build is green on PHPStan level 8, the unit suite, the live
integration suite, and the Behat end-to-end suite across token / user-pass / TLS / TLS-upgrade /
NKey / JWT servers.

Heads-up: this release contains intentional, bug-/spec-driven backward-incompatible changes.
See Breaking changes below before upgrading.


⚠️ Breaking changes

  1. Object Store rewritten to the official NATS layout (data-format break). Chunks are now stored
    under $O.<bucket>.C.<nuid>, the digest is base64url, meta subjects are base64-encoded, and the
    meta record carries nuid (was chunk_subject). Buckets written by 1.x are not readable by
    2.0 and vice-versa.
    Upside: buckets are now interoperable with the nats CLI and the official
    clients. Migrate by re-uploading objects with 2.0.

  2. ObjectInfo::$chunkSubject removed → renamed to $nuid (and a new ?int $revision was
    added). Read $info->nuid instead of $info->chunkSubject; positional new ObjectInfo(...)
    construction changed.

  3. ObjectStoreBucket::get() on a deleted object now returns null (was an ObjectData with the
    deleted flag set). Use info() to observe a tombstone.

  4. Service endpoints now share queue group "q" by default (addEndpoint() default
    $queueGroup changed null → "q"). Multiple instances of a service now load-balance (one
    instance handles each request) per the NATS micro spec, instead of fan-out (every instance handled
    every request). To keep fan-out, pass queueGroup: null.

  5. TransportInterface gained a required upgradeTls(): Future method, and readLine() must now
    signal peer-close (EOF) by throwing TransportClosedException instead of returning ''. Custom
    transport implementations must be updated.

  6. SubscriptionQueue::next() with no timeout configured is now non-blocking (a single bounded
    cycle returning null when nothing is immediately available), instead of blocking until a message
    arrives. Configure a timeout if you need a bounded wait.

Validation tightening (rejecting already-invalid input — bad header names, dotted/consecutive-dot KV
keys, dotted bucket names, oversized frames/control lines, non-positive chunk size) is deliberately
scoped to invalid usage and does not affect valid callers.


✨ New features

  • flush() on NatsClient/NatsConnection — PING/PONG round-trip confirming the server has
    processed prior writes (e.g. a SUBSCRIBE before a dependent request).
  • ObjectStoreBucket::putStream() — memory-bounded streaming upload from a producer callback
    (the counterpart to getToCallback()); blocks of any size are re-chunked, pipelined, and hashed
    incrementally.
  • JetStream Direct Get API — directGetStreamMessage(), directGetLastMessageForSubject(), and
    streamSequenceOf(). KeyValue get()/getAll() and Object Store info()/get()/list() read
    via Direct Get (served by any replica), with automatic fallback to leader STREAM.MSG.GET when a
    stream has allow_direct disabled.
  • Standard post-INFO TLS upgrade path with a TlsAwareTransportInterface, plus the
    tlsHandshakeFirst option wired through.
  • Service per-endpoint metadata (addEndpoint(..., metadata:)), advertised in $SRV.INFO, and
    spec-compliant queue-group load balancing by default.
  • processIncoming(?Cancellation) accepts an optional cancellation; ObjectInfo::revision is now
    populated; SubscriptionQueue gained unsubscribe()/close().

🐛 Correctness & robustness fixes

Connection / reconnect

  • Idle connections no longer self-disconnect; the heartbeat survives without an active read loop.
  • Request/fetch timeouts no longer orphan an in-flight socket read (no spurious reconnects / consumed
    replies) — reads are cancellation-aware.
  • Subscription dispatch is non-reentrant per SID: a handler that awaits on the connection (e.g.
    ordered-consumer recovery) can no longer be re-entered by a heartbeat tick or nested request,
    eliminating ordered-consumer state corruption and overlapping/duplicate delivery.
  • Reconnect no longer deadlocks when a callback publishes during subscription replay.
  • drain() always closes the socket and clears state, even on a fatal frame mid-flush.
  • The CONNECT frame advertises the resolved client version.

JetStream

  • Ordered consumers deliver in order without duplicates or recreate-storms.
  • Domain-qualified 11-token $JS.ACK subjects are parsed (gap detection + revision work on
    domain/leaf deployments).
  • Flow-control stall heartbeats are answered on the Nats-Consumer-Stalled subject (throttled
    consumers no longer hang).
  • publish()/publishScheduled() translate no-responders into a JetStreamException (503).

KeyValue / Object Store

  • KeyValue getAll() paginates the subjects map (no silent truncation) and surfaces API errors.
  • Object Store purges previous chunks on overwrite/delete, paginates list(), fast-paths single-chunk
    downloads via Direct Get, and verifies the digest by bytes (tolerating unpadded base64url).
  • Malformed JSON replies surface as JetStreamException (not a raw JsonException).

Services / protocol / security

  • Endpoint error replies carry the micro-spec Nats-Service-Error / Nats-Service-Error-Code
    headers; start() is atomic with rollback; observers always receive request_end.
  • The parser bounds unterminated control lines (1 MiB) and rejects integer-overflowing size/sid
    fields.
  • replyTo, header names/values, and bucket names are validated (protocol-injection safe); the NKey
    seed is zeroed after key derivation and checked against any configured nkey; the handshake-first TLS
    path no longer risks writing credentials in cleartext.

⚡ Performance

  • KeyValue getAll() and Object Store list() read all records concurrently via Direct Get.
  • Object Store put()/delete() overlap the previous-revision lookup with the upload; single-chunk
    downloads take one round-trip; putStream() re-chunks in O(n).
  • Header wire blocks are built once per publish; the per-chunk subscription drain stays proportional to
    pending subscriptions.

Upgrade notes

  • Requires PHP 8.2+ and amphp/amp v3.
  • Re-upload Object Store objects (1.x bucket data is not readable by 2.0).
  • Multi-instance services now load-balance by default — pass queueGroup: null to addEndpoint() to
    restore fan-out.
  • Custom TransportInterface implementations must add upgradeTls() and throw
    TransportClosedException on EOF.

Full per-change detail with test references is in CHANGELOG.md.