File tree Expand file tree Collapse file tree 1 file changed +18
-4
lines changed
packages/transport-webrtc/src Expand file tree Collapse file tree 1 file changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -207,16 +207,30 @@ export class WebRTCStream extends AbstractStream {
207207 options ?. signal ?. throwIfAborted ( )
208208 this . receivedFinAck = Promise . withResolvers < void > ( )
209209
210+ // don't wait for FIN_ACK forever
211+ const signal = options ?. signal ?? AbortSignal . timeout ( this . finAckTimeout )
212+
213+ // allow cleaning up event promises
214+ const eventPromises = [
215+ pEvent ( this . channel , 'close' , {
216+ signal
217+ } ) ,
218+ pEvent ( this . channel , 'error' , {
219+ signal
220+ } )
221+ ]
222+
210223 // wait for either:
211224 // 1. the FIN_ACK to be received
212225 // 2. the datachannel to close
213226 // 3. timeout
214227 await Promise . any ( [
215- raceSignal ( this . receivedFinAck . promise , options ?. signal ) ,
216- pEvent ( this . channel , 'close' ) ,
217- pEvent ( this . channel , 'error' ) ,
218- pEvent ( AbortSignal . timeout ( this . finAckTimeout ) , 'abort' )
228+ raceSignal ( this . receivedFinAck . promise , signal ) ,
229+ ...eventPromises
219230 ] )
231+ . finally ( ( ) => {
232+ eventPromises . forEach ( p => p . cancel ( ) )
233+ } )
220234 }
221235
222236 async sendCloseRead ( options ?: AbortOptions ) : Promise < void > {
You can’t perform that action at this time.
0 commit comments