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

Socket.io cannot create 2nd server, error: TypeError: wsModule.Server is not a constructor #521

Closed
1 of 2 tasks
dennisat opened this issue Jul 29, 2017 · 3 comments
Closed
1 of 2 tasks

Comments

@dennisat
Copy link

dennisat commented Jul 29, 2017

You want to:

  • report a bug
  • request a feature

Current behaviour

Cannot create two servers in the same node instance.

Steps to reproduce (if the current behaviour is a bug)

This test fails.

The wsServer2 cannot be created, we get a exception caught in the try catch block. The strange is that the 1st server, the wsServer1 is created with no exception.

Probably the creation should be done with different way... but how?

    var http = require('http');
    var engineIo = require('engine.io');
    var httpServer1;
    var httpServer2;
    var wsServer1;
    var wsServer2;
    describe('socket.io test basics', function () {
        it('should create server 1', function () {
            try {
                httpServer1 = http.createServer();
                wsServer1 = engineIo(httpServer1);
                httpServer1.listen(34001);
                expect(true).toBe(true);
            }
            catch (error) {
                console.error('cannot create server 1', error);
                expect(!!error).toBe(false);
            }
        });
        it('should create server 2', function () {
            try {
                httpServer2 = http.createServer();
                wsServer2 = engineIo(httpServer2);
                httpServer2.listen(34002);
                expect(true).toBe(true);
            }
            catch (error) {
                console.error('cannot create server 2', error);
                expect(!!error).toBe(false);
            }
        });
    });

The exception is this:

 TypeError: wsModule.Server is not a constructor
        at Server.Object.<anonymous>.Server.init (L:\myApp\node_modules\engine.io\lib\server.js:121:13)
        at new Server (L:\myApp\node_modules\engine.io\lib\server.js:65:8)
        at attach (L:\myApp\node_modules\engine.io\lib\engine.io.js:123:16)
        at Object.<anonymous>.module.exports (L:\myApp\node_modules\engine.io\lib\engine.io.js:24:19)
        at Object.it (L:\myApp\tests\socket.io.test.ts:26:25)
        at Object.asyncFn (L:\myApp\node_modules\jest-jasmine2\build\jasmine-async.js:68:30)
        at resolve (L:\myApp\node_modules\jest-jasmine2\build\queueRunner.js:38:12)
        at mapper (L:\myApp\node_modules\jest-jasmine2\build\queueRunner.js:31:21)
        at Promise.resolve.then.el (L:\myApp\node_modules\p-map\index.js:42:16)
        at process._tickCallback (internal/process/next_tick.js:103:7)

Expected behaviour

No errors. the 2nd server should be created as the first one did.

Setup

  • OS: window
  • browser: nodejs 7.2.0
  • engine.io version: 2.0.3

Other information (e.g. stacktraces, related issues, suggestions how to fix)

@KevinW1998
Copy link

I've had the same issue. It seems that it is a issue with uws. If it fails to use uws it will fallback to ws (expection is thrown and catched). If this happens a second time the fallback fails (exception is not thrown) but the wsModule is set to undefined. Therefor the error.

A temporary workaround is to use the ws module.

@leaysgur
Copy link

leaysgur commented Nov 30, 2017

I've had the same issue too.
And my case, it was because make command does not installed and failed to build uws.

My workaround is to modify code like

wsServer1 = engineIo(httpServer1, { wsEngine: 'ws' });

or wsEngine can be set by process.env.EIO_WS_ENGINE.
https://github.com/socketio/engine.io/blob/master/lib/server.js#L39

darrachequesne added a commit that referenced this issue May 8, 2020
@darrachequesne
Copy link
Member

Closed due to inactivity, please reopen if needed.

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

4 participants