Skip to content

Commit

Permalink
ble/sagas: add workaround for BlueZ quirk
Browse files Browse the repository at this point in the history
The 'gattserverdisconnected' event is called before the device is
actually disconnected, so if the user tries to connect again
immediately, the web browser will show a still "paired" device, but
selecting this devices results in an infinite wait. This is a bug in
Chromium, but we can work around it by adding a delay to give BlueZ
time to actually disconnect the device.

Closes: pybricks/support#600
  • Loading branch information
dlech committed Oct 26, 2022
1 parent 57c87da commit 509c635
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/ble/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
import { firmwareInstallPybricks } from '../firmware/actions';
import { RootState } from '../reducers';
import { ensureError } from '../utils';
import { isLinux } from '../utils/os';
import { pythonVersionToSemver } from '../utils/version';
import {
bleConnectPybricks as bleConnectPybricks,
Expand Down Expand Up @@ -433,6 +434,16 @@ function* handleBleConnectPybricks(): Generator {
// wait for disconnection
yield* take(disconnectChannel);

// HACK: Disconnection event comes early on Linux, so scanning again
// can show that the previous connection is still "paired" and trying
// to select it results in infinite wait. To work around this, we need
// to wait long enough for BlueZ to actually disconnect the device.
// https://github.com/pybricks/support/issues/600#issuecomment-1286606624
// istanbul ignore if
if (process.env.NODE_ENV !== 'test' && isLinux()) {
yield* delay(5000);
}

yield* put(bleDidDisconnectPybricks());
} catch (err) {
// istanbul ignore if
Expand Down

0 comments on commit 509c635

Please sign in to comment.