question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot read property 'handleUpgrade' of undefined

See original GitHub issue

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 7e50871c418a6fcffd211d72c3abe1a09035b52e as the init method is only called when attach is used.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

0reactions
exsiliumcommented, Jan 29, 2017

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property 'handleUpgrade' of ...
That's why the error occur, ws is undefined. Here is a simple piece of code reproducing the error: var ioClient = require('socket.io-client'); ...
Read more >
How to deal with server.handleUpgrade() was called more ...
Well, In My project I was using express-monitor which was also using socket.io hence leading the server to handle the upgrade for ws...
Read more >
[NODE-3192] Cannot read property 'clusterTime' of undefined
When making a rolling restart of my Atlas cluster, this error is sometimes thrown when the client looses or re-establishes the connection, ...
Read more >
T12755 Aphlict doesn't work with the latest version of `ws`
TypeError : Cannot read property 'url' of undefined at WebSocketServer. ... (events.js:106:13) at WebSocketServer.emit (events.js:191:7) at handleUpgrade ...
Read more >
Node-red crashes on calling editor.stop() - General
4 Sep 16:04:37 - TypeError: Cannot read property 'handleUpgrade' of null ... a Function node that doesn't have direct access to the internals...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found