Skip to content

Commit

Permalink
fix: catch some quantel releasePort errors (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian authored Oct 22, 2021
1 parent 7af7f83 commit 10007c2
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions packages/timeline-state-resolver/src/devices/quantel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,8 +697,13 @@ class QuantelManager extends EventEmitter {
port = await this._quantel.getPort(cmd.portId)
}
if (port) {
// port already exists, release it first:
await this._quantel.releasePort(cmd.portId)
try {
// port already exists, release it first:
await this._quantel.releasePort(cmd.portId)
} catch (e) {
// we should still try to create the port even if we can't release the old one
this.emit('warning', `setupPort release failed: ${e.toString()}`)
}
}
await this._quantel.createPort(cmd.portId, cmd.channel)

Expand All @@ -717,10 +722,22 @@ class QuantelManager extends EventEmitter {
try {
const channel = this._quantelState.port[cmd.portId].channel

{
// Before doing anything, wait for an existing releasePort to finish:
const existingRelease = this.waitingForReleaseChannel.get(channel)
if (existingRelease) await existingRelease
}

const p = this._quantel.releasePort(cmd.portId)
this.waitingForReleaseChannel.set(channel, p)

// Create a promise for others to wait on, that will never reject
const waitP = p.catch().then(() => {
this.waitingForReleaseChannel.delete(channel)
})
this.waitingForReleaseChannel.set(channel, waitP)

// Wait for the release
await p
this.waitingForReleaseChannel.delete(channel)
} catch (e) {
if (e.status !== 404) {
// releasing a non-existent port is OK
Expand Down

0 comments on commit 10007c2

Please sign in to comment.