Skip to content

Send LAN_LOGOFF on disconnect#11

Merged
jaak0b merged 1 commit into
mainfrom
fix/logoff-on-disconnect
Jun 27, 2026
Merged

Send LAN_LOGOFF on disconnect#11
jaak0b merged 1 commit into
mainfrom
fix/logoff-on-disconnect

Conversation

@jaak0b

@jaak0b jaak0b commented Jun 27, 2026

Copy link
Copy Markdown
Owner

Problem

Z21CommandStation.DisconnectAsync closed the UDP socket without sending LAN_LOGOFF, so the Z21 kept the client's slot registered (~60s). Repeated connect/disconnect cycles accumulate stale slots and exhaust the command station's client/subscription table; the reconnected client then stops receiving LAN_X_LOCO_INFO broadcasts (loco-specific per-subscriber forwarding is dropped) while global broadcasts like LAN_SYSTEMSTATE_DATACHANGED keep arriving. Observed on hardware as "loco updates stop after a reconnect, but feedback/system state still work."

Change

DisconnectAsync now sends LogOffCommand (LAN_LOGOFF, 0x0030) before closing the transport, so the Z21 frees the slot immediately. The send is guarded by IsConnected and wrapped in try/catch (logged) so the transport is always closed even if the logoff send fails.

Tests

  • DisconnectAsync_SendsLogOffThenDisconnects
  • DisconnectAsync_WhenNotConnected_DoesNotSendLogOff
  • DisconnectAsync_WhenLogOffSendFails_StillDisconnects (via new FakeTransport.ThrowOnSend)

Full Z21.Client suite green (695 tests).

@jaak0b jaak0b merged commit 999afdc into main Jun 27, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant