@@ -3308,7 +3308,7 @@ describe('WebSocket', () => {
33083308 } ) ;
33093309 } ) ;
33103310
3311- describe ( 'Connection close edge cases ' , ( ) => {
3311+ describe ( 'Connection close' , ( ) => {
33123312 it ( 'closes cleanly after simultaneous errors (1/2)' , ( done ) => {
33133313 let clientCloseEventEmitted = false ;
33143314 let serverClientCloseEventEmitted = false ;
@@ -3420,5 +3420,59 @@ describe('WebSocket', () => {
34203420 } ) ;
34213421 } ) ;
34223422 } ) ;
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+ } ) ;
34233477 } ) ;
34243478} ) ;
0 commit comments