{"action":"closed","issue":{"url":"https://api.github.com/repos/socketio/engine.io/issues/442","repository_url":"https://api.github.com/repos/socketio/engine.io","labels_url":"https://api.github.com/repos/socketio/engine.io/issues/442/labels{/name}","comments_url":"https://api.github.com/repos/socketio/engine.io/issues/442/comments","events_url":"https://api.github.com/repos/socketio/engine.io/issues/442/events","html_url":"https://github.com/socketio/engine.io/issues/442","id":187100507,"number":442,"title":"Uncaught TypeError: Cannot read property 'handleUpgrade' of undefined","user":{"login":"veloce48","id":20637422,"avatar_url":"https://avatars.githubusercontent.com/u/20637422?v=3","gravatar_id":"","url":"https://api.github.com/users/veloce48","html_url":"https://github.com/veloce48","followers_url":"https://api.github.com/users/veloce48/followers","following_url":"https://api.github.com/users/veloce48/following{/other_user}","gists_url":"https://api.github.com/users/veloce48/gists{/gist_id}","starred_url":"https://api.github.com/users/veloce48/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/veloce48/subscriptions","organizations_url":"https://api.github.com/users/veloce48/orgs","repos_url":"https://api.github.com/users/veloce48/repos","events_url":"https://api.github.com/users/veloce48/events{/privacy}","received_events_url":"https://api.github.com/users/veloce48/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-11-03T15:46:39Z","updated_at":"2016-11-15T21:01:20Z","closed_at":"2016-11-15T21:01:20Z","body":"After upgrading socket.io to version 1.5.1, I got the following error (it didn't occur with socket.io 1.5.0):\r\n\r\n```\r\nUncaught TypeError: Cannot read property 'handleUpgrade' of undefined\r\n      at node_modules\\engine.io\\lib\\server.js:343:12\r\n      at Server.verify (node_modules\\engine.io\\lib\\server.js:162:3)\r\n      at Server.handleUpgrade (node_modules\\engine.io\\lib\\server.js:332:8)\r\n      at Server.<anonymous> (node_modules\\engine.io\\lib\\server.js:453:14)\r\n      at onParserExecuteCommon (_http_server.js:409:14)\r\n      at HTTPParser.onParserExecute (_http_server.js:377:5)\r\n```\r\n\r\nThe error comes from engine.io, whose version has been updated to 1.7.2 through the update of socket.io to 1.5.1. I searched in the code of server.js, and found that the guilty line is:\r\n\r\n```\r\nself.ws.handleUpgrade(req, socket, head, function(conn){\r\n    self.onWebSocket(req, conn);\r\n});\r\n```\r\n\r\nThe field `ws` is instantiated in the constructor of the `Server` object (server.js line 75):\r\n\r\n```\r\nthis.ws = new WebSocketServer({\r\n    noServer: true,\r\n    clientTracking: false,\r\n    perMessageDeflate: this.perMessageDeflate,\r\n    maxPayload: this.maxHttpBufferSize\r\n});\r\n```\r\n\r\nBut when you close the server with the `close()` function, we see in the code of server.js (line 182 to 195) that the field `ws` is deleted:\r\n\r\n```\r\nif (this.ws) {\r\n    debug('closing webSocketServer');\r\n    this.ws.close();\r\n    delete this.ws;\r\n}\r\n```\r\n\r\n And this was not the case in previous version of engine.io. This field is not instantiated again when you call the `listen()` function later on your server. That's why the error occur, `ws` is undefined.\r\n\r\nHere is a simple piece of code reproducing the error:\r\n\r\n```\r\nvar ioClient = require('socket.io-client');\r\nvar express = require('express');\r\nvar http = express();\r\nvar server = require('http').Server(http);\r\nvar io = require('socket.io')(server);\r\n\r\nio.on('connection', function (socket) {\r\n\tconsole.log('connection :', socket.id);\r\n});\r\n\r\nserver.listen(80, function () {\r\n\t// do some stuff ...\r\n\tserver.close(); // ws is deleted\r\n\tserver.listen(80, function () {\r\n\t\tvar socket = ioClient.connect('http://localhost');\r\n\t\t// the socket will trigger a call to handleUpgrade() function\r\n\t\t// and the error will occur\r\n\t});\r\n});\r\n```\r\n\r\nTry to run this code with a previous version of engine.io (through socket.io 1.5.0 eg) and the error will not occur. With the latest version of engine.io (through socket.io 1.5.1), the error will occur.\r\n\r\nIs this a real issue, or am I missing something ?\r\n\r\n"}}
{"actor":{"display_login":"darrachequesne"}}