Skip to content
This repository

TypeError: Cannot call method 'addListener' of undefined #90

Closed
njam opened this Issue · 13 comments

3 participants

Reto Kaiser Marek Bryce Kahle
Reto Kaiser

Hi,

we're running quite a busy SockJS 0.3.3 server (4000 concurrent connections), and sometimes see this error in our logs:

error   Exception on "POST /stream/547/88ni42ue/xhr" in filter "xhr_poll":
TypeError: Cannot call method 'addListener' of undefined
    at XhrPollingReceiver.GenericReceiver.setUp (/usr/lib/node_modules/socket-redis/node_modules/sockjs/lib/transport.js:268:19)
    at XhrPollingReceiver.GenericReceiver (/usr/lib/node_modules/socket-redis/node_modules/sockjs/lib/transport.js:260:12)
    at XhrPollingReceiver.ResponseReceiver (/usr/lib/node_modules/socket-redis/node_modules/sockjs/lib/transport.js:326:46)
    at XhrPollingReceiver.XhrStreamingReceiver (/usr/lib/node_modules/socket-redis/node_modules/sockjs/lib/trans-xhr.js:15:50)
    at new XhrPollingReceiver (/usr/lib/node_modules/socket-redis/node_modules/sockjs/lib/trans-xhr.js:33:48)
    at App.exports.app.xhr_poll (/usr/lib/node_modules/socket-redis/node_modules/sockjs/lib/trans-xhr.js:104:37)
    at execute_request (/usr/lib/node_modules/socket-redis/node_modules/sockjs/lib/webjs.js:21:38)
    at IncomingMessage.exports.generateHandler.req.next_filter (/usr/lib/node_modules/socket-redis/node_modules/sockjs/lib/webjs.js:95:18)
    at Listener.exports.generateHandler [as webjs_handler] (/usr/lib/node_modules/socket-redis/node_modules/sockjs/lib/webjs.js:97:13)
    at Listener.handler (/usr/lib/node_modules/socket-redis/node_modules/sockjs/lib/sockjs.js:141:12)

It's not often, around 10 times a day.

Kind regards

Marek
Owner

Hmm, interesting. Do you know how to trigger that? Do you use haproxy or something? ssl or http? What version of node and sockjs?

Reto Kaiser

Hey majek,

we have a pretty basic setup using direct http and:
node 0.8.10
sockJS 0.3.3

Unfortunately I don't know how to reproduce the exception.

As it is not happening often it's not a big issue for us. Just thought maybe you see at a glance what could be the problem.
If not you can also close this ticket and I will reopen if I have further information.

Regards

Marek
Owner

Hmm, interesting.

Looks like res.connection is undefined, for some reason. It would be great to figure out why and when, maybe some particular broken browser or ISP?

In the meantime, can you check if my guess is right? Please apply this patch (or something among the lines):

diff --git a/src/trans-xhr.coffee b/src/trans-xhr.coffee
index e245712..f71beb4 100644
--- a/src/trans-xhr.coffee
+++ b/src/trans-xhr.coffee
@@ -72,6 +72,10 @@ exports.app =
         res.setHeader('Content-Type', 'application/javascript; charset=UTF-8')
         res.writeHead(200)

+        if not res.connection
+            console.log("Lack of connection object on xhr_poll")
+            return true
+
         transport.register(req, @, new XhrPollingReceiver(res, @options))
         return true

After you've done it, please let me know if the crashes stopped appearing. If so, please add some more debugging data to the console.log, maybe referrer, user agent, ip address and so on. Hopefully with this data we'll be able to identify the cause of this crash.

Reto Kaiser

Hey majek,

I applied the patch you suggested, but this doesn't seem to be the problem. I still see the original exception.

Regards,
Reto

Marek
Owner

1) Thanks for trying it out!
2) Back to the drawing board...

Marek
Owner

I'm out of ideas, sorry. You did apply my changes to xhr_poll function, right? Maybe the traceback is now different?

Marek
Owner

Also, did you compile the .coffee to .js (ie: is the updated code actually used?)?

Reto Kaiser

I put it directly into the JS. It might be that the traceback was different and it was then xhr_streaming.
I'm now testing both. I'll update as soon as I have new log entries.

Reto Kaiser

Is console.log() going to sockJS' log() function? If not how can I log to the internal sockJS logging function?

Marek
Owner

no, console.log is nodejs thing. @log("blah") should send the string to sockjs logger.

Reto Kaiser

So you were completely right, there's no res.connection in xhr_poll and xhr_streaming:

error Lack of connection object on xhr_poll
error Lack of connection object on xhr_streaming

I'm now also logging the request headers and will update as soon as I have some.

Reto Kaiser

Hey majek,

so here's the request headers so far which produce this error:

error   Lack of connection object on xhr_streaming:
{
    "host": "1533.stream.(foo).com:8093",
    "accept-encoding": "gzip",
    "accept-language": "en-US",
    "accept-charset": "utf-8, iso-8859-1, utf-16, *;q=0.7",
    "referer": "http://www.(foo).com/bar",
    "user-agent": "Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; SPH-D700 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
    "origin": "http://www.(foo).com",
    "accept": "text/xml, text/html, application/xhtml+xml, image/png, text/plain, */*;q=0.8",
    "x-wap-profile": "http://device.sprintpcs.com/Samsung/SPH-D700/FC09.rdf",
    "content-length": "0"
}

error   Lack of connection object on xhr_poll:
{
    "host": "4179.stream.(foo).com:8090",
    "accept-encoding": "gzip",
    "accept-language": "en-US",
    "x-wap-profile": "http://uaprof.motorola.com/phoneconfig/motomb865/Profile/motomb865.rdf",
    "accept-charset": "utf-8, iso-8859-1, utf-16, *;q=0.7",
    "referer": "http://www.(foo).com/home",
    "user-agent": "Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; MB865 Build/5.5.1-175_EDMR1.25) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
    "x-att-deviceid": "MOT-MB865/Blur_Version.55.13.25.MB865.ATT.en.US Flex/P015",
    "origin": "http://www.(foo).com",
    "accept": "text/xml, text/html, application/xhtml+xml, image/png, text/plain, */*;q=0.8",
    "content-length": "0"
}

error   Lack of connection object on xhr_streaming:
{
    "host": "571.stream.(foo).com:8093",
    "accept-encoding": "gzip",
    "accept-language": "en-US",
    "x-wap-profile": "http://uaprof.metropcs.net/UAProf/LG-MS840.xml",
    "accept-charset": "utf-8, iso-8859-1, utf-16, *;q=0.7",
    "referer": "http://www.(foo).com/bar",
    "user-agent": "Mozilla/5.0 (Linux; U; Android 2.3.6; en-us; LG-MS840 Build/GRK39F) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
    "origin": "http://www.(foo).com",
    "accept": "text/xml, text/html, application/xhtml+xml, image/png, text/plain, */*;q=0.8",
    "content-length": "0"
}

error   Lack of connection object on xhr_streaming:
{
    "host": "1759.stream.(foo).com:8092",
    "accept-encoding": "gzip",
    "accept-language": "en-US",
    "x-wap-profile": "http://www.htcmms.com.tw/Android/Common/PG88/ua-profile.xml",
    "accept-charset": "utf-8, iso-8859-1, utf-16, *;q=0.7",
    "referer": "http://www.(foo).com/home",
    "user-agent": "Mozilla/5.0 (Linux; U; Android 2.3.3; en-us; HTC_DesireS_S510e Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
    "origin": "http://www.(foo).com",
    "accept": "text/xml, text/html, application/xhtml+xml, image/png, text/plain, */*;q=0.8",
    "content-length": "0"
}

error   Lack of connection object on xhr_poll:
{
    "host": "3631.stream.(foo).com:8090",
    "accept-encoding": "gzip",
    "accept-language": "fr-CA, en-US",
    "x-wap-profile": "http://wap.sonyericsson.com/UAprof/X10aR301.xml",
    "accept-charset": "utf-8, iso-8859-1, utf-16, *;q=0.7",
    "referer": "http://www.(foo).com/home",
    "user-agent": "Mozilla/5.0 (Linux; U; Android 2.3.3; fr-ca; SonyEricssonX10a Build/3.0.1.G.0.75) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
    "origin": "http://www.(foo).com",
    "accept": "text/xml, text/html, application/xhtml+xml, image/png, text/plain, */*;q=0.8",
    "content-length": "0"
}

All Android 2.3, all have the "x-wap-profile" header..

Paweł Ledwoń pl referenced this issue from a commit in pl/sockjs-node
Paweł Ledwoń pl Fix issue #90
* pass request to ResponseReceiver
* use req.connection instead of res.connection
f0fe7e8
Marek majek referenced this issue from a commit
Paweł Ledwoń pl Fix issue #90
* pass request to ResponseReceiver
* use req.connection instead of res.connection
6ea8191
Bryce Kahle brycekahle closed this
Reto Kaiser
njam commented

jep, doesn't happen anymore. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.