Cannot call method 'writeHead' of undefined
I'm getting this in 0.8.6
I'm not sure which browser connected or caused the problem, this is just something I found in my err.log trying to figure out the reason for a crash.
/home/ubuntu/www/node_modules/socket.io/lib/transports/jsonp-polling.js:87
this.response.writeHead(200, {
^
TypeError: Cannot call method 'writeHead' of undefined
at JSONPPolling.doWrite (/home/ubuntu/www/node_modules/socket.io/lib/transports/jsonp-polling.js:87:17)
at JSONPPolling.write (/home/ubuntu/www/node_modules/socket.io/lib/transports/http-polling.js:120:8)
at JSONPPolling.packet (/home/ubuntu/www/node_modules/socket.io/lib/transport.js:515:15)
at JSONPPolling.error (/home/ubuntu/www/node_modules/socket.io/lib/transport.js:498:8)
at JSONPPolling.onData (/home/ubuntu/www/node_modules/socket.io/lib/transports/jsonp-polling.js:68:10)
at IncomingMessage.<anonymous> (/home/ubuntu/www/node_modules/socket.io/lib/transports/http.js:60:12)
at IncomingMessage.emit (events.js:61:17)
at HTTPParser.onMessageComplete (http.js:133:23)
at Socket.ondata (http.js:1008:22)
at Socket._onReadable (net.js:681:27)
Back to 0.8.5 for now.
@guille this https://github.com/LearnBoost/socket.io/blob/master/lib/transports/jsonp-polling.js#L68 causes it :p
I don't really know why..
getting the same error
Hey,
in my opinion this is source of problem
https://github.com/LearnBoost/socket.io/blob/master/lib/transports/http.js#L72
so the response is set only for request req.method != 'POST' but onData is called for req.method == 'POST'
+1. I'll try to take a look at it tonight; surprised more people haven't run into this.
Have the same problem. Happens usually after system is up for a while
Have same issue with 0.8.7, but I'm unable to replicate it reliably. Happens on heavy load, with 400 clients connected and 20+ connecting/disconecting per second.
I had the issue. I found out that I forgot to encode the message in the POST method. Here a example
T 192.168.10.1:57908 -> 192.168.10.141:3000 [AP] POST /socket.io/1/jsonp-polling/1897756582168726773?i=0 HTTP/1.1. Host: 192.168.10.141:3000. Connection: keep-alive. Accept: /. User-Agent: NING/1.0. Content-Length: 65. . "5:1+::{"name":"nickname","args":["test_1324996401409"]}"
GOOD WAY HERE
Content-Length: 111. . d=%225%3A1%2B%3A%3A%7B%5C%22name%5C%22%3A%5C%22nickname%5C%22%2C%5C%22args%5C%22%3A%5B%5C%22test%5C%22%5D%7D%22
Hope that can help.
I also have this issue, but it's only after a few days of execution of my node/socket.io program, still don't know the exact reason.
Survivant, I am not sure that I'm following your answer. Are you saying that we should encode the arguments to the socket.send function?
Thanks for the help.
Anybody have any news about this bug?
I'm currently looking into this.
Great! Gracias!
Having the same problem here.
DEBUG: /root/node/node_modules/socket.io/lib/transports/jsonp-polling.js:87
DEBUG: this.response.writeHead(200, {
DEBUG:
DEBUG: ^
DEBUG: TypeError: Cannot call method 'writeHead' of undefined
at JSONPPolling.doWrite (/root/node/node_modules/socket.io/lib/transports/jsonp-polling.js:87:17)
at JSONPPolling.write (/root/node/node_modules/socket.io/lib/transports/http-polling.js:120:8)
at JSONPPolling.packet (/root/node/node_modules/socket.io/lib/transport.js:515:15)
at JSONPPolling.error (/root/node/node_modules/socket.io/lib/transport.js:498:8)
at JSONPPolling.onData (/root/node/node_modules/socket.io/lib/transports/jsonp-polling.js:68:10)
at IncomingMessage.
+1 on this bug, happens randomly, sometimes 5 min, sometimes 20 hours.
+1, have same problems.
The quick fix is to remove jsonp-polling from transports. e.g. socket.set('transports', [ 'websocket', 'htmlfile', 'xhr-polling' ]);
thank you men
Any ETA on this? It's still an issue.
+1 I'm seeing this on 0.8.7 similar sort of behaviour to what DefV describes.
Might be unrelated, but my upgrade to 0.9.0 has dramatically increased the occurrences of this error.
Do you see this only with jsonp ? Or also xhr-polling ?