Skip to content

*: detecting abrupt disconnections in Linux#408

Open
sorayaormazabalmayo wants to merge 1 commit intotinygo-org:devfrom
sorayaormazabalmayo:feature/abrupt-disconnection-linux
Open

*: detecting abrupt disconnections in Linux#408
sorayaormazabalmayo wants to merge 1 commit intotinygo-org:devfrom
sorayaormazabalmayo:feature/abrupt-disconnection-linux

Conversation

@sorayaormazabalmayo
Copy link

This PR implements persistent D-Bus signal monitoring at the adapter level to detect abrupt disconnections. The connectHandler callback was not being invoked when Bluetooth devices disconnected abruptly (e.g., device powered off, out of range, battery died) on Linux. It only worked for planned disconnections via Device.Disconnect(). This created an inconsistency with the Darwin implementation, which correctly detects all disconnections through CoreBluetooth's DidDisconnectPeripheral delegate method.

@deadprogram deadprogram changed the base branch from release to dev February 10, 2026 11:40
@sorayaormazabalmayo sorayaormazabalmayo force-pushed the feature/abrupt-disconnection-linux branch 2 times, most recently from 904e54e to 2818558 Compare February 11, 2026 11:05
}

a.monitoringConnections = true
go a.handleConnectionSignals()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sorayaormazabalmayo I think there needs to be a way to stop this goroutine cleanly on exit.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right @deadprogram! I have just added StopConnectionMonitoring that unregisters the D-Bus signal handlers, closes channels, and sets monitoringConnections to false. Also, the select loop in handleConnectionSignals listens on stopMonitorChan so the goroutine exits immediately on shutdown.

@sorayaormazabalmayo sorayaormazabalmayo force-pushed the feature/abrupt-disconnection-linux branch from 2818558 to 8455a42 Compare February 26, 2026 11:18
This PR implements persistent D-Bus signal monitoring at the adapter
level to detect abrupt disconnections. The `connectHandler` callback was
not being invoked when Bluetooth devices disconnected abruptly (e.g.,
device powered off, out of range, battery died) on Linux. It only worked
for planned disconnections via `Device.Disconnect()`. This created an
inconsistency with the Darwin implementation, which correctly detects
all disconnections through CoreBluetooth's `DidDisconnectPeripheral`
delegate method.
@sorayaormazabalmayo sorayaormazabalmayo force-pushed the feature/abrupt-disconnection-linux branch from 8455a42 to 196598c Compare February 26, 2026 11:35
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.

2 participants