@@ -3308,7 +3308,7 @@ describe('WebSocket', () => {
3308
3308
} ) ;
3309
3309
} ) ;
3310
3310
3311
- describe ( 'Connection close edge cases ' , ( ) => {
3311
+ describe ( 'Connection close' , ( ) => {
3312
3312
it ( 'closes cleanly after simultaneous errors (1/2)' , ( done ) => {
3313
3313
let clientCloseEventEmitted = false ;
3314
3314
let serverClientCloseEventEmitted = false ;
@@ -3420,5 +3420,59 @@ describe('WebSocket', () => {
3420
3420
} ) ;
3421
3421
} ) ;
3422
3422
} ) ;
3423
+
3424
+ it ( 'resumes the socket when an error occurs' , ( done ) => {
3425
+ const maxPayload = 16 * 1024 ;
3426
+ const wss = new WebSocket . Server ( { maxPayload, port : 0 } , ( ) => {
3427
+ const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
3428
+ } ) ;
3429
+
3430
+ wss . on ( 'connection' , ( ws ) => {
3431
+ const list = [
3432
+ ...Sender . frame ( Buffer . alloc ( maxPayload + 1 ) , {
3433
+ fin : true ,
3434
+ opcode : 0x02 ,
3435
+ mask : true ,
3436
+ readOnly : false
3437
+ } )
3438
+ ] ;
3439
+
3440
+ ws . on ( 'error' , ( err ) => {
3441
+ assert . ok ( err instanceof RangeError ) ;
3442
+ assert . strictEqual ( err . code , 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH' ) ;
3443
+ assert . strictEqual ( err . message , 'Max payload size exceeded' ) ;
3444
+
3445
+ ws . on ( 'close' , ( code , reason ) => {
3446
+ assert . strictEqual ( code , 1006 ) ;
3447
+ assert . strictEqual ( reason , EMPTY_BUFFER ) ;
3448
+ wss . close ( done ) ;
3449
+ } ) ;
3450
+ } ) ;
3451
+
3452
+ ws . _socket . push ( Buffer . concat ( list ) ) ;
3453
+ } ) ;
3454
+ } ) ;
3455
+
3456
+ it ( 'resumes the socket when the close frame is received' , ( done ) => {
3457
+ const wss = new WebSocket . Server ( { port : 0 } , ( ) => {
3458
+ const ws = new WebSocket ( `ws://localhost:${ wss . address ( ) . port } ` ) ;
3459
+ } ) ;
3460
+
3461
+ wss . on ( 'connection' , ( ws ) => {
3462
+ const opts = { fin : true , mask : true , readOnly : false } ;
3463
+ const list = [
3464
+ ...Sender . frame ( Buffer . alloc ( 16 * 1024 ) , { opcode : 0x02 , ...opts } ) ,
3465
+ ...Sender . frame ( EMPTY_BUFFER , { opcode : 0x08 , ...opts } )
3466
+ ] ;
3467
+
3468
+ ws . on ( 'close' , ( code , reason ) => {
3469
+ assert . strictEqual ( code , 1005 ) ;
3470
+ assert . strictEqual ( reason , EMPTY_BUFFER ) ;
3471
+ wss . close ( done ) ;
3472
+ } ) ;
3473
+
3474
+ ws . _socket . push ( Buffer . concat ( list ) ) ;
3475
+ } ) ;
3476
+ } ) ;
3423
3477
} ) ;
3424
3478
} ) ;
0 commit comments