Skip to content

Commit

Permalink
feat(bluetooth): reset stuck Bluetooth adapters
Browse files Browse the repository at this point in the history
If the inquiry command does not return at all anymore the adapter should
also be reset. This can be observed by looking for the promise timeouts.
  • Loading branch information
mKeRix committed Dec 13, 2020
1 parent 4cdeb24 commit ab4e940
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/integrations/bluetooth/bluetooth.service.spec.ts
Expand Up @@ -94,6 +94,14 @@ describe('BluetoothService', () => {
expect(mockExec).toHaveBeenCalledWith('hciconfig hci1 reset');
});

it('should reset the HCI device if the command execution times out', async () => {
mockExec.mockRejectedValue({ message: 'timed out' });

const result = await service.inquireClassicRssi(1, '08:05:90:ed:3b:60');
expect(result).toBeUndefined();
expect(mockExec).toHaveBeenCalledWith('hciconfig hci1 reset');
});

it('should stop scanning on an adapter while performing an inquiry', async () => {
service.onLowEnergyDiscovery(() => undefined);
const stateChangeHandler = mockNoble.on.mock.calls[0][1];
Expand Down
8 changes: 7 additions & 1 deletion src/integrations/bluetooth/bluetooth.service.ts
Expand Up @@ -169,8 +169,14 @@ export class BluetoothService {
e.message?.includes('I/O')
) {
this.logger.debug(e.message);
} else if (e.message == 'timed out') {
this.logger.warn(
`Bluetooth adapter ${adapterId} seems stuck, resetting`
);
this.healthIndicator.reportError();
await this.resetHciDevice(adapterId);
} else {
this.logger.error(e.message);
this.logger.error(`Inquiring RSSI via BT Classic failed: ${e.message}`);
this.healthIndicator.reportError();
}

Expand Down

0 comments on commit ab4e940

Please sign in to comment.