Skip to content

Commit

Permalink
fix(hci): Possible fixes for timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Crespi committed May 17, 2021
1 parent a982fa1 commit 16fbb91
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 25 deletions.
8 changes: 4 additions & 4 deletions lib/bindings/hci/Adapter.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/bindings/hci/Adapter.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/bindings/hci/misc/Hci.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 10 additions & 7 deletions lib/bindings/hci/misc/Hci.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/bindings/hci/misc/Hci.js.map

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/bindings/hci/Adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { HciGattLocal } from './gatt';
import { Gap, Hci } from './misc';
import { HciPeripheral } from './Peripheral';

const SCAN_ENABLE_TIMEOUT = 1000;
const ADVERTISING_ENABLE_TIMEOUT = 1000;
const SCAN_ENABLE_TIMEOUT = 5000;
const ADVERTISING_ENABLE_TIMEOUT = 5000;

interface Advertisement {
localName: string;
Expand Down Expand Up @@ -300,7 +300,7 @@ export class HciAdapter extends Adapter {
this.scanEnableTimer = setTimeout(() => enableScanning(), SCAN_ENABLE_TIMEOUT);
});
};
enableScanning();
this.scanEnableTimer = setTimeout(() => enableScanning(), SCAN_ENABLE_TIMEOUT);
}
};

Expand All @@ -318,7 +318,7 @@ export class HciAdapter extends Adapter {
this.advertisingEnableTimer = setTimeout(() => enableAdvertising(), ADVERTISING_ENABLE_TIMEOUT);
});
};
enableAdvertising();
this.advertisingEnableTimer = setTimeout(() => enableAdvertising(), ADVERTISING_ENABLE_TIMEOUT);
}
};

Expand Down
17 changes: 10 additions & 7 deletions src/bindings/hci/misc/Hci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,12 +631,6 @@ export class Hci extends TypedEmitter<HciEvents> {
};

const rejectHandler = async (error?: Error) => {
try {
await this.cancelLeConn();
} catch {
// NO-OP
}

cleanup();

if (error) {
Expand All @@ -649,7 +643,16 @@ export class Hci extends TypedEmitter<HciEvents> {
this.on('leConnComplete', onComplete);

const timeoutError = new HciError(`Creating connection timed out`);
timeout = setTimeout(() => rejectHandler(timeoutError), 2 * this.cmdTimeout);
timeout = setTimeout(async () => {
// If we timed out we should cancel our connection attempt
try {
await this.cancelLeConn();
} catch {
// NO-OP
}

rejectHandler(timeoutError);
}, this.connTimeout);

this.sendCommand(cmd, true).catch((err) => rejectHandler(err));
});
Expand Down

0 comments on commit 16fbb91

Please sign in to comment.