Skip to content

Closing handshake is broken when maxPayload is exceeded #784

@lpinca

Description

@lpinca

Description

When maxPayloadExceeded is called, the dead flag is set on the Receiver.
This makes the Receiver ignore everything including the final close frame coming from the other peer to complete the closing handshake.
Since the handshake cannot be completed, the connection is only closed when the cleanup timeout expires.

Test case:

'use strict';

const WebSocket = require('ws');
const http = require('http');

const server = http.createServer();
const wss = new WebSocket.Server({
  perMessageDeflate: false,
  clientTracking: false,
  maxPayload: 10,
  server
});

wss.on('connection', (ws) => {
  ws.on('error', (err) => {
    console.log(err.stack);
    ws.close();
    server.close();
  });
  ws.on('message', () => {
    ws.close();
    server.close();
  });
});

server.listen(3000, () => {
  const ws = new WebSocket('ws://localhost:3000');
  ws.on('open', () => ws.send('0123456789'));
});

The process exits only when the cleanup timeout expires.
If the maxPayload option is removed, the process exits immediately as expected.

@LordMajestros, since you have implemented the feature, do you have any idea on how to fix this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions