socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

Cannot call method 'writeHead' of undefined

Open Charuru opened this issue 15 years ago • 39 comments

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.

Charuru avatar Nov 01 '11 05:11 Charuru

@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..

3rd-Eden avatar Nov 01 '11 08:11 3rd-Eden

getting the same error

tommypowerz avatar Nov 01 '11 20:11 tommypowerz

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'

dymsza avatar Nov 12 '11 16:11 dymsza

+1. I'll try to take a look at it tonight; surprised more people haven't run into this.

mogest avatar Nov 21 '11 20:11 mogest

Have the same problem. Happens usually after system is up for a while

ghost avatar Nov 25 '11 20:11 ghost

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.

lekoder avatar Nov 28 '11 07:11 lekoder

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.

survivant avatar Dec 27 '11 23:12 survivant

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.

ghost avatar Dec 28 '11 10:12 ghost

Anybody have any news about this bug?

ghost avatar Jan 09 '12 08:01 ghost

I'm currently looking into this.

rauchg avatar Jan 10 '12 16:01 rauchg

Great! Gracias!

ghost avatar Jan 11 '12 08:01 ghost

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. (/root/node/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:1029:22) at Socket._onReadable (net.js:687:27)

andremoniz avatar Jan 18 '12 18:01 andremoniz

+1 on this bug, happens randomly, sometimes 5 min, sometimes 20 hours.

DefV avatar Jan 20 '12 08:01 DefV

+1, have same problems.

hwndept avatar Feb 14 '12 13:02 hwndept

The quick fix is to remove jsonp-polling from transports. e.g. socket.set('transports', [ 'websocket', 'htmlfile', 'xhr-polling' ]);

sokac avatar Feb 22 '12 01:02 sokac

thank you men

hwndept avatar Feb 22 '12 09:02 hwndept

Any ETA on this? It's still an issue.

DavidChouinard avatar Feb 26 '12 03:02 DavidChouinard

+1 I'm seeing this on 0.8.7 similar sort of behaviour to what DefV describes.

user-dotcom avatar Feb 28 '12 13:02 user-dotcom

Might be unrelated, but my upgrade to 0.9.0 has dramatically increased the occurrences of this error.

DavidChouinard avatar Feb 28 '12 20:02 DavidChouinard

Do you see this only with jsonp ? Or also xhr-polling ?

rauchg avatar Feb 28 '12 20:02 rauchg