Repository navigation
v2.0.0 — hardening + official Object Store interop
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
-
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 carriesnuid(waschunk_subject). Buckets written by 1.x are not readable by
2.0 and vice-versa. Upside: buckets are now interoperable with thenatsCLI and the official
clients. Migrate by re-uploading objects with 2.0. -
ObjectInfo::$chunkSubjectremoved → renamed to$nuid(and a new?int $revisionwas
added). Read$info->nuidinstead of$info->chunkSubject; positionalnew ObjectInfo(...)
construction changed. -
ObjectStoreBucket::get()on a deleted object now returnsnull(was anObjectDatawith the
deletedflag set). Useinfo()to observe a tombstone. -
Service endpoints now share queue group
"q"by default (addEndpoint()default
$queueGroupchangednull→"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, passqueueGroup: null. -
TransportInterfacegained a requiredupgradeTls(): Futuremethod, andreadLine()must now
signal peer-close (EOF) by throwingTransportClosedExceptioninstead of returning''. Custom
transport implementations must be updated. -
SubscriptionQueue::next()with no timeout configured is now non-blocking (a single bounded
cycle returningnullwhen 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()onNatsClient/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 togetToCallback()); blocks of any size are re-chunked, pipelined, and hashed
incrementally.- JetStream Direct Get API —
directGetStreamMessage(),directGetLastMessageForSubject(), and
streamSequenceOf(). KeyValueget()/getAll()and Object Storeinfo()/get()/list()read
via Direct Get (served by any replica), with automatic fallback to leaderSTREAM.MSG.GETwhen a
stream hasallow_directdisabled. - Standard post-INFO TLS upgrade path with a
TlsAwareTransportInterface, plus the
tlsHandshakeFirstoption 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::revisionis now
populated;SubscriptionQueuegainedunsubscribe()/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.ACKsubjects are parsed (gap detection + revision work on
domain/leaf deployments). - Flow-control stall heartbeats are answered on the
Nats-Consumer-Stalledsubject (throttled
consumers no longer hang). publish()/publishScheduled()translate no-responders into aJetStreamException(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 rawJsonException).
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 receiverequest_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 Storelist()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: nulltoaddEndpoint()to
restore fan-out. - Custom
TransportInterfaceimplementations must addupgradeTls()and throw
TransportClosedExceptionon EOF.
Full per-change detail with test references is in CHANGELOG.md.