LearnBoost/socket.io — Issue #620: TypeError at WebSocket.onSocketConnect crashes app on Heroku. Locally, app runs fine
Author: matt-hickford
Created: 2011-11-02 20:44:25+00:00
State: open

Hi. I've a bug that crashes an app on Heroku but not locally. The app uses the framework [Zappa](https://github.com/mauricemach/zappa). If you think the bug is in Zappa or Heroku, please tell me, and I'll report it there. I'm reporting it here because the crash is in socket.io

Here's the crash

2011-11-02T20:12:42+00:00 heroku[web.1]: State changed from crashed to created
2011-11-02T20:12:42+00:00 heroku[web.1]: State changed from created to starting
2011-11-02T20:12:44+00:00 app[web.1]: info - socket.io started

app[web.1]: Express server listening on port 59785 in development mode
2011-11-02T20:12:44+00:00 app[web.1]: Zappa 0.3.1 "The Gumbo Variations" orchestrating the show
2011-11-02T20:12:45+00:00 heroku[web.1]: State changed from starting to up
2011-11-02T20:12:57+00:00 heroku[router]: GET megablogger.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=11ms status=200 bytes=281
2011-11-02T20:12:58+00:00 app[web.1]: debug - served static content /socket.io.js
2011-11-02T20:12:59+00:00 app[web.1]: debug - client authorized
2011-11-02T20:12:59+00:00 app[web.1]: info - handshake authorized 18865551101085978027
2011-11-02T20:12:59+00:00 app[web.1]: debug - setting request GET /socket.io/1/websocket/18865551101085978027
2011-11-02T20:12:59+00:00 app[web.1]: debug - set heartbeat interval for client 18865551101085978027
2011-11-02T20:12:59+00:00 app[web.1]:
2011-11-02T20:12:59+00:00 app[web.1]: /app/node_modules/zappa/node_modules/socket.io/lib/transports/websocket/hybi-07-12.js:94
2011-11-02T20:12:59+00:00 app[web.1]: if (this.req.headers.upgrade.toLowerCase() !== 'websocket') {
2011-11-02T20:12:59+00:00 app[web.1]: at Manager.handleClient (/app/node_modules/zappa/node_modules/socket.io/lib/manager.js:626:19)
2011-11-02T20:12:59+00:00 app[web.1]: at Manager.handleHTTPRequest (/app/node_modules/zappa/node_modules/socket.io/lib/manager.js:597:8)
2011-11-02T20:12:59+00:00 app[web.1]: at Manager.handleRequest (/app/node_modules/zappa/node_modules/socket.io/lib/manager.js:559:12)
2011-11-02T20:12:59+00:00 app[web.1]: at HTTPServer. (/app/node_modules/zappa/node_modules/socket.io/lib/manager.js:107:10)
2011-11-02T20:12:59+00:00 heroku[router]: Error H13 (Connection closed without response) -> GET megablogger.herokuapp.com/socket.io/1/websocket/18865551101085978027 dyno=web.1 queue= wait= service= status=503 bytes=
2011-11-02T20:12:59+00:00 app[web.1]: at HTTPServer.emit (events.js:67:17)
2011-11-02T20:12:59+00:00 heroku[web.1]: Process exited
2011-11-02T20:13:00+00:00 heroku[web.1]: State changed from up to crashed
2011-11-02T20:13:09+00:00 heroku[router]: Error H10 (App crashed) -> GET megablogger.herokuapp.com/socket.io/1/xhr-polling/18865551101085978027 dyno= queue= wait= service= status=503 bytes=

Someone else reported the same crash at https://github.com/LearnBoost/socket.io/issues/602 but they couldn't reproduce it. I've just put a lot of work into reproducing it. Here's how you can do it:

git clone -b socket-crash https://github.com/matt-hickford/megablogger.git
cd megablogger
git checkout socket-crash
cat package.json
npm install
coffee megablogger.coffee

This runs the app at localhost:5000 . Open that in your web browser in a couple of tabs. Refresh. There is no crash.

Now deploy to Heroku (assumes you have a Heroku account and the ruby gem `heroku` installed)

heroku create --stack cedar
git push heroku socket-crash:master
heroku logs -t

Now browse to the deployed Heroku app. Watch the app crash. Press refresh, see the sad Heroku error message.