Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection hangs on falsy verifyClient result #1572

Closed
JozefFlakus opened this issue May 24, 2019 · 3 comments
Closed

Connection hangs on falsy verifyClient result #1572

JozefFlakus opened this issue May 24, 2019 · 3 comments

Comments

@JozefFlakus
Copy link

JozefFlakus commented May 24, 2019

Description

At the beginning, I have to say - many thanks for this library. ws is the lib of choice and was integrated exclusively with Marble.js framework. 💪

The issue is very strange because suddenly it started to occur. The problem is probably with refusing a connection inside verifyClient method. If the verifyClient method refuses connection then the client hangs and timeouts after some time. An interesting fact is that it occurs even in the simple ws server. I typically tested it on Chrome browsers (via some client extensions) and one week ago it worked properly. To be honest I'm not sure if some Chrome update introduced some breaking changes to the WebSocket communication during the handshake phase 🤔

Reproducible in:

  • version: 7.0.0 (tested also on 6.x.x)
  • Node.js version(s): 10.15.0
  • OS version(s): macOS
  • browser client (Chrome 74.0.3729.169)

Steps to reproduce:

import * as WebSocket from 'ws';

const ws = new WebSocket.Server({
  port: 8080,
  host: '127.0.0.1',
  verifyClient: (info, cb) => cb(false),
});

ws.on('connection', () => {
  console.log('connected');
});

Expected result:

  • the connection is refused (a proper error is triggered)

Actual result:

  • the connection hangs and timeouts after some time

Attachments:

Zrzut ekranu 2019-05-24 o 20 28 14

@lpinca
Copy link
Member

lpinca commented May 25, 2019

I can't reproduce with Chrome 74.0.3729.169 on macOS.

'use strict';

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

const data = `<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
  </head>
  <body>
    <script>
      (function () {
        var ws = new WebSocket('ws://localhost:8080');

        ws.onopen = function () {
          console.log('open');
        };
      })();
    </script>
  </body>
</html>`;

const server = http.createServer();

server.on('request', function(req, res) {
  res.setHeader('Content-Type', 'text/html');
  res.end(data);
});

const wss = new WebSocket.Server({
  server,
  verifyClient(info, cb) {
    cb(false);
  }
});

wss.on('connection', function() {
  console.log('connected');
});

server.listen(8080, function() {
  console.log('Server listening on [::]:8080');
});

Screenshot 2019-05-25 at 08 35 49

@JozefFlakus
Copy link
Author

It turned out that some extension that was installed interfered with WebSocket connection. The strangest thing is that it only occurred when then the connection was refused.

Anyway, now it works. Thanks again @lpinca!

@lpinca
Copy link
Member

lpinca commented May 25, 2019

Anyway, my suggestion is to not use the verifyClient hook, see #377 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants