Files
floci/docs
Mario Toffia 87aa6f38a1 feat(iot): publish connection lifecycle events (#5277)
* feat(iot): publish connection lifecycle events

The MQTT broker publishes $aws/events/presence/connected and disconnected
for every session, with its session identifier, certificate principal,
version number and disconnect reason, through topic rules and to
subscribers. Topic filters starting with a wildcard no longer match $ topics,
as on AWS.

Closes #5275

* fix(iot): keep lifecycle events within the reset guard

A lifecycle event admits its topic rules under the rule state at the time
of the event, so one queued before an emulator reset skips them. A
DeleteConnection that wins the session tolerates an endpoint the client's
DISCONNECT already closed.

* fix(iot): serialize session transitions and report keep-alive timeouts

Admission, takeover, DeleteConnection and session end now allocate the
versionNumber and change the session map under one lock, with endpoint
I/O kept outside it. A takeover of an endpoint that is already closed
still accepts the new connection.

A close after a full keep-alive period without a packet from the client
is reported as MQTT_KEEP_ALIVE_TIMEOUT, as AWS IoT does. The WebSocket
upgrade carries the client's port, and the wildcard-first exclusion is
limited to the lifecycle topics, which AWS does not deliver to such
filters while it does deliver shadow topics.

* fix(iot): keep ended sessions out of subscriptions and time keep-alive from CONNECT

* test(iot): drive keep-alive tests from an injected nano-time source

The broker takes a LongSupplier nano-time source, as ReloadingKeyManager
does, so the keep-alive unit tests move a fake clock forward instead of
sleeping. The race test uses ThreadStates.awaitBlockedOrDone.
2026-10-19 16:18:54 -04:00
..
2026-03-15 17:43:56 -05:00