@@ -251,7 +251,7 @@ class QUICConnection extends EventTarget {
251
251
}
252
252
253
253
/**
254
- * This provides the ability to destroy with a specific error
254
+ * This provides the ability to destroy with a specific error. This will wait for the connection to fully drain.
255
255
*/
256
256
public async destroy (
257
257
{
@@ -289,7 +289,7 @@ class QUICConnection extends EventTarget {
289
289
}
290
290
}
291
291
// If it is not closed, it could still be draining
292
- if ( ! this . conn . isClosed ( ) ) {
292
+ if ( this . conn . isDraining ( ) ) {
293
293
// The `recv`, `send`, `timeout`, and `on_timeout` should continue to be called
294
294
const { p : closeP , resolveP : resolveCloseP } = utils . promise ( ) ;
295
295
this . resolveCloseP = resolveCloseP ;
@@ -300,6 +300,11 @@ class QUICConnection extends EventTarget {
300
300
}
301
301
this . connectionMap . delete ( this . connectionId ) ;
302
302
this . dispatchEvent ( new events . QUICConnectionDestroyEvent ( ) ) ;
303
+ // Clean up timeout
304
+ if ( this . timer != null ) {
305
+ clearTimeout ( this . timer ) ;
306
+ delete this . timer ;
307
+ }
303
308
this . logger . info ( `Destroyed ${ this . constructor . name } ` ) ;
304
309
}
305
310
@@ -339,6 +344,9 @@ class QUICConnection extends EventTarget {
339
344
this . logger . debug ( `Did a recv ${ data . byteLength } ` ) ;
340
345
this . conn . recv ( data , recvInfo ) ;
341
346
} catch ( e ) {
347
+ this . logger . error ( e . toString ( ) ) ;
348
+ // console.error(e);
349
+ // console.log(this.conn.isClosed());
342
350
// Depending on the exception, the `this.conn.recv`
343
351
// may have automatically started closing the connection
344
352
this . dispatchEvent (
@@ -427,13 +435,12 @@ class QUICConnection extends EventTarget {
427
435
428
436
try {
429
437
if ( this . conn . isClosed ( ) ) {
430
-
431
-
432
438
if ( this . resolveCloseP != null ) this . resolveCloseP ( ) ;
433
439
return ;
434
- } else if ( this . conn . isDraining ( ) ) {
435
- return ;
436
440
}
441
+ // else if (this.conn.isDraining()) {
442
+ // return;
443
+ // }
437
444
const sendBuffer = new Uint8Array ( quiche . MAX_DATAGRAM_SIZE ) ;
438
445
let sendLength : number ;
439
446
let sendInfo : SendInfo ;
@@ -481,7 +488,7 @@ class QUICConnection extends EventTarget {
481
488
sendInfo . to . host
482
489
) ;
483
490
} catch ( e ) {
484
- console . error ( e ) ;
491
+ this . logger . error ( e . toString ( ) )
485
492
this . dispatchEvent ( new events . QUICConnectionErrorEvent ( { detail : e } ) ) ;
486
493
return ;
487
494
}
@@ -491,11 +498,12 @@ class QUICConnection extends EventTarget {
491
498
this . logger . debug ( 'SEND FINALLY' ) ;
492
499
493
500
this . setTimeout ( ) ;
501
+ this . logger . debug ( `connection is closed?: ${ this . conn . isClosed ( ) } ` )
502
+ this . logger . debug ( `connection is draining?: ${ this . conn . isDraining ( ) } ` )
494
503
if (
495
504
this [ status ] !== 'destroying' &&
496
505
( this . conn . isClosed ( ) || this . conn . isDraining ( ) )
497
506
) {
498
-
499
507
this . logger . debug ( 'CALLING DESTROY' ) ;
500
508
501
509
await this . destroy ( ) ;
0 commit comments