I wrote a simple Node.js WebSocket chat server. To run the server, I'm using foreman start
with a Procfile
that merely contains the line: chat: npm start
.
I also wrote an iPhone app that uses SocketRocket to connect to the aforementioned server. In applicationDidEnterBackground:
, I call close
on webSocket
. And, In applicationWillEnterForeground:
, I recreate webSocket
and call open
.
When entering the background or foreground, the iPhone app seems to crash the server with the error:
chat.1 | events.js:74
chat.1 | throw TypeError('Uncaught, unspecified "error" event.');
chat.1 | ^
chat.1 | TypeError: Uncaught, unspecified "error" event.
chat.1 | at TypeError (<anonymous>)
chat.1 | at WebSocket.EventEmitter.emit (events.js:74:15)
chat.1 | at Receiver.self._receiver.onerror (~/Projects/Chat/node_modules/ws/lib/WebSocket.js:719:10)
chat.1 | at Receiver.error (~/Projects/Chat/node_modules/ws/lib/Receiver.js:301:8)
chat.1 | at Receiver.opcodes.8.finish (~/Projects/Chat/node_modules/ws/lib/Receiver.js:497:14)
chat.1 | at Receiver.<anonymous> (~/Projects/Chat/node_modules/ws/lib/Receiver.js:478:33)
chat.1 | at Receiver.add (~/Projects/Chat/node_modules/ws/lib/Receiver.js:93:24)
chat.1 | at Socket.firstHandler (~/Projects/Chat/node_modules/ws/lib/WebSocket.js:678:22)
chat.1 | at Socket.EventEmitter.emit (events.js:95:17)
chat.1 | at Socket.<anonymous> (_stream_readable.js:746:14)
chat.1 | npm ERR! weird error 8
chat.1 | npm ERR! not ok code 0
chat.1 | exited with code 1
system | sending SIGTERM to all processes
Why is this happening? And, how do I fix it?