Skip to content

Commit

Permalink
fix(connect): fix potential device hang after received message asseti…
Browse files Browse the repository at this point in the history
…on error
  • Loading branch information
mroz22 committed Jan 22, 2025
1 parent bc385c2 commit 59d6e69
Showing 1 changed file with 14 additions and 4 deletions.
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

0 comments on commit 59d6e69

Please sign in to comment.