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

Cannot read property 'handleUpgrade' of undefined #473

Closed
1 of 2 tasks
lpinca opened this issue Jan 23, 2017 · 6 comments · Fixed by #476
Closed
1 of 2 tasks

Cannot read property 'handleUpgrade' of undefined #473

lpinca opened this issue Jan 23, 2017 · 6 comments · Fixed by #476

Comments

@lpinca
Copy link
Contributor

lpinca commented Jan 23, 2017

Note: for support questions, please use one of these channels: stackoverflow or slack

You want to:

  • report a bug
  • request a feature

Current behaviour

An error is thrown when not using Server.prototype.attach directly or indirectly.

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

Run the following the test case

'use strict';

const eioc = require('engine.io-client');
const eio = require('engine.io');
const http = require('http');

const server = http.createServer();
const engine = new eio.Server();

engine.on('connection', (socket) => {
  socket.on('message', (data) => socket.send(data));
  socket.on('close', () => console.log('close'));
});

server.on('upgrade', (req, socket, head) => {
  engine.handleUpgrade(req, socket, head);
});

server.on('request', (req, res) => {
  engine.handleRequest(req, res);
});

server.listen(3000, () => {
  const socket = eioc('http://localhost:3000');

  socket.on('open', () => socket.send('foo'));
  socket.on('message', (data) => console.log(data));
  socket.on('close', () => console.log('close'));
});

Expected behaviour

The above example should work without throwing errors.

Setup

  • OS: macOS
  • browser: -
  • engine.io version: 2.0.0

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

TypeError: Cannot read property 'handleUpgrade' of undefined
    at /Users/luigi/eio-2.0/node_modules/engine.io/lib/server.js:360:12
    at Server.verify (/Users/luigi/eio-2.0/node_modules/engine.io/lib/server.js:171:3)
    at Server.handleUpgrade (/Users/luigi/eio-2.0/node_modules/engine.io/lib/server.js:349:8)
    at Server.server.on (/Users/luigi/eio-2.0/index.js:16:10)
    at emitThree (events.js:116:13)
    at Server.emit (events.js:194:7)
    at onParserExecuteCommon (_http_server.js:459:14)
    at onParserExecute (_http_server.js:418:3)

It seems that issue has been introduces in 7e50871 as the init method is only called when attach is used.

@lpinca
Copy link
Contributor Author

lpinca commented Jan 24, 2017

This prevents us from upgrading to engine.io@2.0.0 in Primus.

cc: @kapouer

@lpinca
Copy link
Contributor Author

lpinca commented Jan 26, 2017

The same issue also happens when using an already listening server:

'use strict';

const eioc = require('engine.io-client');
const eio = require('engine.io');
const http = require('http');

const server = http.createServer();

server.listen(3000, () => {
  const engine = eio.attach(server);

  engine.on('connection', (socket) => {
    socket.on('message', (data) => socket.send(data));
    socket.on('close', () => console.log('close'));
  });

  const socket = eioc('http://localhost:3000');

  socket.on('open', () => socket.send('foo'));
  socket.on('message', (data) => console.log(data));
  socket.on('close', () => console.log('close'));
});

@exsilium
Copy link

exsilium commented Jan 29, 2017

Hit this myself, any suggestions for a fix?

@lpinca
Copy link
Contributor Author

lpinca commented Jan 29, 2017

@exsilium #459 (comment) or apply this patch.

@exsilium
Copy link

@lpinca Appreciated! :bowtie:

@exsilium
Copy link

I see... @lpinca , As i see #476 being open... I gather it will be eventually be pulled in for 2.0.1? Cheers!

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

Successfully merging a pull request may close this issue.

2 participants