Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connect device communication fixes #16528

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions packages/connect/src/device/Device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import { checkFirmwareRevision } from './checkFirmwareRevision';
import { IStateStorage } from './StateStorage';
import type { PromptCallback } from './prompts';
import { calculateFirmwareHash, getBinaryOptional, stripFwHeaders } from '../api/firmware';

import { cancelPrompt } from './prompts';
// custom log
const _log = initLog('Device');

Expand Down Expand Up @@ -555,10 +555,11 @@ export class Device extends TypedEmitter<DeviceEvents> {
// 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) => {
getFeaturesTimeoutId = setTimeout(
() => reject(new Error('GetFeatures timeout')),
getFeaturesTimeout,
);
getFeaturesTimeoutId = setTimeout(() => {
cancelPrompt(this, false).finally(() => {
reject(new Error('GetFeatures timeout'));
});
}, getFeaturesTimeout);
}),
]);
}
Expand Down
18 changes: 14 additions & 4 deletions packages/connect/src/device/DeviceCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,20 @@ export class DeviceCommands {
} catch (error) {
// handle possible race condition
// Bridge may have some unread message in buffer, read it
await this.transport.receive({
session: this.transportSession,
protocol: this.device.protocol,
});
const abortController = new AbortController();
const timeout = setTimeout(() => {
abortController.abort();
}, 500);

await this.transport
.receive({
session: this.transportSession,
protocol: this.device.protocol,
signal: abortController.signal,
})
.finally(() => {
clearTimeout(timeout);
});
// throw error anyway, next call should be resolved properly
throw error;
}
Expand Down
Loading