Skip to content

Fix LAN dev-connection server leaking port 9000 on stop/reconnect#273

Merged
sjp4 merged 1 commit into
coredevices:masterfrom
bekriebel:fix-dev-connection
Jul 1, 2026
Merged

Fix LAN dev-connection server leaking port 9000 on stop/reconnect#273
sjp4 merged 1 commit into
coredevices:masterfrom
bekriebel:fix-dev-connection

Conversation

@bekriebel

Copy link
Copy Markdown
Contributor

The LAN dev-connection server (port 9000) was never released when dev connection was toggled off or the watch disconnected, and could not rebind on reconnect -- requiring an app force-stop to recover.

startSuspend() returns immediately in this Ktor/CIO engine config, so the restart loop spawned a duplicate server that failed to bind while the real listener leaked unreferenced. stop() then operated on the wrong instance, so the socket was never freed. Additionally, the transport was assigned to last only after start() returns, but start() now suspends indefinitely, so the stop() in teardown always saw null.

Start the server once and await cancellation; record the transport before start(); and explicitly stop() in a finally to free the port on toggle-off and disconnect.

Fixes #219

Co-Authored-By: glm-5.2

Reproduction steps for the issue:

  1. Enable Settings -> Phone -> Connectivity -> Use LAN developer connection
  2. On a device, enable Dev Connection
  3. Using pebble tools, run pebble ping --phone <IP> (works)
  4. Turn off Dev Connection
  5. Run the ping command again and note that it still works, even though the connection should be off
  6. Disconnect the phone either with the Disconnect button, or by toggling Bluetooth on the watch
  7. Reconnect the watch
  8. Turn on Dev Connection
  9. Run the ping command again (fails)

The LAN dev-connection server (port 9000) was never released when dev
connection was toggled off or the watch disconnected, and could not
rebind on reconnect -- requiring an app force-stop to recover.

startSuspend() returns immediately in this Ktor/CIO engine config, so
the restart loop spawned a duplicate server that failed to bind while
the real listener leaked unreferenced. stop() then operated on the
wrong instance, so the socket was never freed. Additionally, the
transport was assigned to `last` only after start() returns, but
start() now suspends indefinitely, so the stop() in teardown always
saw null.

Start the server once and await cancellation; record the transport
before start(); and explicitly stop() in a finally to free the port on
toggle-off and disconnect.

Fixes coredevices#219

Co-Authored-By: glm-5.2
Signed-off-by: Brint E. Kriebel <github@bekit.net>
@sjp4 sjp4 merged commit 3925c0d into coredevices:master Jul 1, 2026
3 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.

LAN developer connection locks up when the watch disconnects unexpectedly

2 participants