@@ -12,6 +12,7 @@ import {
12
12
} from '@matrixai/async-init/dist/CreateDestroy' ;
13
13
import Logger from '@matrixai/logger' ;
14
14
import { Lock } from '@matrixai/async-locks' ;
15
+ import { destroyed } from '@matrixai/async-init' ;
15
16
import QUICStream from './QUICStream' ;
16
17
import { quiche } from './native' ;
17
18
import * as events from './events' ;
@@ -291,11 +292,7 @@ class QUICConnection extends EventTarget {
291
292
await this . closedP ;
292
293
this . logger . debug ( 'closeP resolved' ) ;
293
294
this . connectionMap . delete ( this . connectionId ) ;
294
- // Checking for errors
295
- const localError = this . conn . localError ( ) ;
296
- const peerError = this . conn . peerError ( ) ;
297
- if ( localError != null ) this . logger . error ( JSON . stringify ( localError ) ) ;
298
- if ( peerError != null ) this . logger . error ( JSON . stringify ( peerError ) ) ;
295
+ // Checking if timed out
299
296
if ( this . conn . isTimedOut ( ) ) {
300
297
this . logger . error ( 'Connection timed out' ) ;
301
298
this . dispatchEvent (
@@ -345,11 +342,31 @@ class QUICConnection extends EventTarget {
345
342
this . conn . recv ( data , recvInfo ) ;
346
343
} catch ( e ) {
347
344
this . logger . error ( e . message ) ;
348
- // Console.error(e);
349
- // console.log(this.conn.isClosed());
350
345
// Depending on the exception, the `this.conn.recv`
351
346
// may have automatically started closing the connection
352
- this . dispatchEvent ( new events . QUICConnectionErrorEvent ( { detail : e } ) ) ;
347
+ if ( e . message === 'TlsFail' ) {
348
+ const newError = new errors . ErrorQUICConnectionTLSFailure ( undefined , {
349
+ data : {
350
+ localError : this . conn . localError ( ) ,
351
+ peerError : this . conn . peerError ( ) ,
352
+ } ,
353
+ } ) ;
354
+ this . dispatchEvent (
355
+ new events . QUICConnectionErrorEvent ( { detail : newError } ) ,
356
+ ) ;
357
+ } else {
358
+ this . dispatchEvent (
359
+ new events . QUICConnectionErrorEvent ( {
360
+ detail : new errors . ErrorQUICConnection ( e . message , {
361
+ cause : e ,
362
+ data : {
363
+ localError : this . conn . localError ( ) ,
364
+ peerError : this . conn . peerError ( ) ,
365
+ } ,
366
+ } ) ,
367
+ } ) ,
368
+ ) ;
369
+ }
353
370
return ;
354
371
}
355
372
// Here we can resolve our promises!
@@ -483,7 +500,15 @@ class QUICConnection extends EventTarget {
483
500
}
484
501
}
485
502
this . dispatchEvent (
486
- new events . QUICConnectionErrorEvent ( { detail : e } ) ,
503
+ new events . QUICConnectionErrorEvent ( {
504
+ detail : new errors . ErrorQUICConnection ( e . message , {
505
+ cause : e ,
506
+ data : {
507
+ localError : this . conn . localError ( ) ,
508
+ peerError : this . conn . peerError ( ) ,
509
+ } ,
510
+ } ) ,
511
+ } ) ,
487
512
) ;
488
513
return ;
489
514
}
@@ -610,7 +635,7 @@ class QUICConnection extends EventTarget {
610
635
`state are draining: ${ this . conn . isDraining ( ) } , closed: ${ this . conn . isClosed ( ) } ` ,
611
636
) ;
612
637
this . logger . debug ( 'timeout SEND' ) ;
613
- await this . send ( ) ;
638
+ if ( this [ destroyed ] === false ) await this . send ( ) ;
614
639
this . logger . debug ( 'timeout SENDAFTER' ) ;
615
640
if (
616
641
this [ status ] !== 'destroying' &&
0 commit comments