Skip to content

Commit

Permalink
fix(connect): clear initial GetFeatures timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonlesisz committed Jan 13, 2025
1 parent 492044c commit 7612092
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/connect/src/device/Device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -542,22 +542,24 @@ export class Device extends TypedEmitter<DeviceEvents> {
? GET_FEATURES_TIMEOUT_REACT_NATIVE
: GET_FEATURES_TIMEOUT;

let getFeaturesTimeoutId: ReturnType<typeof setTimeout> | undefined;

// do not initialize while firstRunPromise otherwise `features.session_id` could be affected
await Promise.race([
this.getFeatures(),
this.getFeatures().finally(() => clearTimeout(getFeaturesTimeoutId)),
// note: tested on 24.7.2024 and whatever is written below this line is still valid
// We do not support T1B1 <1.9.0 but we still need Features even from not supported devices to determine your version
// and tell you that update is required.
// Edge-case: T1B1 + bootloader < 1.4.0 doesn't know the "GetFeatures" message yet and it will send no response to its
// transport response is pending endlessly, calling any other message will end up with "device call in progress"
// set the timeout for this call so whenever it happens "unacquired device" will be created instead
// next time device should be called together with "Initialize" (calling "acquireDevice" from the UI)
new Promise((_resolve, reject) =>
setTimeout(
new Promise((_resolve, reject) => {
getFeaturesTimeoutId = setTimeout(
() => reject(new Error('GetFeatures timeout')),
getFeaturesTimeout,
),
),
);
}),
]);
}
} catch (error) {
Expand Down

0 comments on commit 7612092

Please sign in to comment.