@@ -46,7 +46,6 @@ class QUICConnection extends EventTarget {
46
46
protected codeToReason : StreamCodeToReason ;
47
47
protected maxReadableStreamBytes : number | undefined ;
48
48
protected maxWritableStreamBytes : number | undefined ;
49
- protected destroyingMap : Map < StreamId , QUICStream > = new Map ( ) ;
50
49
51
50
// This basically allows one to await this promise
52
51
// once resolved, always resolved...
@@ -421,7 +420,7 @@ class QUICConnection extends EventTarget {
421
420
} ;
422
421
try {
423
422
this . conn . recv ( data , recvInfo ) ;
424
- this . logger . debug ( `RECEIVED ${ data . byteLength } of data` ) ;
423
+ this . logger . info ( `RECEIVED ${ data . byteLength } of data` ) ;
425
424
} catch ( e ) {
426
425
this . logger . error ( `recv error ${ e . message } ` ) ;
427
426
// Depending on the exception, the `this.conn.recv`
@@ -460,18 +459,15 @@ class QUICConnection extends EventTarget {
460
459
if ( this . resolveCloseP != null ) this . resolveCloseP ( ) ;
461
460
return ;
462
461
}
463
- if (
464
- ! this . conn . isDraining ( ) &&
465
- ( this . conn . isInEarlyData ( ) || this . conn . isEstablished ( ) )
466
- ) {
462
+ if ( this . conn . isInEarlyData ( ) || this . conn . isEstablished ( ) ) {
463
+ const readIds : Array < number > = [ ] ;
467
464
for ( const streamId of this . conn . readable ( ) as Iterable < StreamId > ) {
468
465
let quicStream = this . streamMap . get ( streamId ) ;
469
466
if ( quicStream == null ) {
470
467
// The creation will set itself to the stream map
471
468
quicStream = await QUICStream . createQUICStream ( {
472
469
streamId,
473
470
connection : this ,
474
- destroyingMap : this . destroyingMap ,
475
471
codeToReason : this . codeToReason ,
476
472
reasonToCode : this . reasonToCode ,
477
473
maxReadableStreamBytes : this . maxReadableStreamBytes ,
@@ -482,9 +478,14 @@ class QUICConnection extends EventTarget {
482
478
new events . QUICConnectionStreamEvent ( { detail : quicStream } ) ,
483
479
) ;
484
480
}
481
+ readIds . push ( quicStream . streamId ) ;
485
482
quicStream . read ( ) ;
486
483
quicStream . dispatchEvent ( new events . QUICStreamReadableEvent ( ) ) ;
487
484
}
485
+ if ( readIds . length > 0 ) {
486
+ this . logger . info ( `processed reads for ${ readIds } ` ) ;
487
+ }
488
+ const writeIds : Array < number > = [ ] ;
488
489
for ( const streamId of this . conn . writable ( ) as Iterable < StreamId > ) {
489
490
let quicStream = this . streamMap . get ( streamId ) ;
490
491
if ( quicStream == null ) {
@@ -494,7 +495,6 @@ class QUICConnection extends EventTarget {
494
495
connection : this ,
495
496
codeToReason : this . codeToReason ,
496
497
reasonToCode : this . reasonToCode ,
497
- destroyingMap : this . destroyingMap ,
498
498
maxReadableStreamBytes : this . maxReadableStreamBytes ,
499
499
logger : this . logger . getChild ( `${ QUICStream . name } ${ streamId } ` ) ,
500
500
} ) ;
@@ -503,18 +503,15 @@ class QUICConnection extends EventTarget {
503
503
) ;
504
504
}
505
505
quicStream . dispatchEvent ( new events . QUICStreamWritableEvent ( ) ) ;
506
+ writeIds . push ( quicStream . streamId ) ;
506
507
quicStream . write ( ) ;
507
508
}
508
- // Checking shortlist if streams have finished.
509
- for ( const [ streamId , stream ] of this . destroyingMap ) {
510
- if ( stream . isFinished ( ) ) {
511
- // If it has finished, it will trigger its own clean up.
512
- // Remove the stream from the shortlist.
513
- this . destroyingMap . delete ( streamId ) ;
514
- }
509
+ if ( writeIds . length > 0 ) {
510
+ this . logger . info ( `processed writes for ${ writeIds } ` ) ;
515
511
}
516
512
}
517
513
} finally {
514
+ this . garbageCollectStreams ( 'recv' ) ;
518
515
this . logger . debug ( 'RECV FINALLY' ) ;
519
516
// Set the timeout
520
517
this . checkTimeout ( ) ;
@@ -527,7 +524,7 @@ class QUICConnection extends EventTarget {
527
524
) {
528
525
this . logger . debug ( 'CALLING DESTROY 2' ) ;
529
526
// Destroy in the background, we still need to process packets
530
- void this . destroy ( ) ;
527
+ void this . destroy ( ) . catch ( ( ) => { } ) ;
531
528
}
532
529
}
533
530
}
@@ -558,6 +555,7 @@ class QUICConnection extends EventTarget {
558
555
} else if ( this . conn . isDraining ( ) ) {
559
556
return ;
560
557
}
558
+ let numSent = 0 ;
561
559
try {
562
560
const sendBuffer = new Uint8Array ( quiche . MAX_DATAGRAM_SIZE ) ;
563
561
let sendLength : number ;
@@ -630,8 +628,10 @@ class QUICConnection extends EventTarget {
630
628
return ;
631
629
}
632
630
this . dispatchEvent ( new events . QUICConnectionSendEvent ( ) ) ;
631
+ numSent += 1 ;
633
632
}
634
633
} finally {
634
+ if ( numSent > 0 ) this . garbageCollectStreams ( 'send' ) ;
635
635
this . logger . debug ( 'SEND FINALLY' ) ;
636
636
this . checkTimeout ( ) ;
637
637
if (
@@ -689,7 +689,6 @@ class QUICConnection extends EventTarget {
689
689
connection : this ,
690
690
codeToReason : this . codeToReason ,
691
691
reasonToCode : this . reasonToCode ,
692
- destroyingMap : this . destroyingMap ,
693
692
maxReadableStreamBytes : this . maxReadableStreamBytes ,
694
693
maxWritableStreamBytes : this . maxWritableStreamBytes ,
695
694
logger : this . logger . getChild ( `${ QUICStream . name } ${ streamId ! } ` ) ,
@@ -743,7 +742,7 @@ class QUICConnection extends EventTarget {
743
742
) {
744
743
this . logger . debug ( 'CALLING DESTROY 3' ) ;
745
744
// Destroy in the background, we still need to process packets
746
- void this . destroy ( ) ;
745
+ void this . destroy ( ) . catch ( ( ) => { } ) ;
747
746
}
748
747
this . checkTimeout ( ) ;
749
748
} ;
@@ -795,6 +794,19 @@ class QUICConnection extends EventTarget {
795
794
}
796
795
}
797
796
} ;
797
+
798
+ protected garbageCollectStreams ( where : string ) {
799
+ const nums : Array < number > = [ ] ;
800
+ // Only check if packets were sent
801
+ for ( const [ streamId , quicStream ] of this . streamMap ) {
802
+ // Stream sending can finish after a packet is sent
803
+ nums . push ( streamId ) ;
804
+ quicStream . read ( ) ;
805
+ }
806
+ if ( nums . length > 0 ) {
807
+ this . logger . info ( `checking read finally ${ where } for ${ nums } ` ) ;
808
+ }
809
+ }
798
810
}
799
811
800
812
export default QUICConnection ;
0 commit comments