Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Problem with ServerResponse emitting close - http server crashes #2570

Closed
Kami opened this issue Jan 18, 2012 · 6 comments
Closed

Problem with ServerResponse emitting close - http server crashes #2570

Kami opened this issue Jan 18, 2012 · 6 comments
Labels

Comments

@Kami
Copy link

Kami commented Jan 18, 2012

When I hit an http server with curl it crashes with the following exception:

Uncaught TypeError: Cannot call method 'emit' of null
    at Socket.onServerResponseClose (http.js:780:21)
    at Socket.emit (events.js:88:20)
    at Array.<anonymous> (net.js:320:10)
    at EventEmitter._tickCallback (node.js:192:40)
----------------------------------------
    at EventEmitter.on
    at ServerResponse.assignSocket (http.js:786:10)
    at HTTPParser.onIncoming (http.js:1454:11)
    at HTTPParser.onHeadersComplete (http.js:102:31)
    at Socket.ondata (http.js:1387:22)
    at TCP.onread (net.js:354:27)
Uncaught undefined

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick

It seems to be related to commit dd9593c. If I revert this commit, the server doesn't crashes.

My first impression was that it has something to do with how the curl closes the connection, but so far I haven't been able to create an isolated test case yet which reproduces it.

I will dig deeper into it tomorrow and try to come up with a test case which reproduces it.

@koichik
Copy link

koichik commented Jan 18, 2012

@Kami - Thanks for the report, can you please get the log with NODE_DEBUG?

$ NODE_DEBUG=net,http node xxx.js

@Kami
Copy link
Author

Kami commented Jan 18, 2012

@koichik Here is the output with debug on:

NET: onconnection
HTTP: SERVER new http connection
HTTP: server response shouldKeepAlive: true
HTTP: outgoing message end.
NET: destroy
NET: close
HTTP: server socket close
Uncaught TypeError: Cannot call method 'emit' of null
    at Socket.onServerResponseClose (http.js:780:21)
    at Socket.emit (events.js:88:20)
    at Array.<anonymous> (net.js:320:10)
    at EventEmitter._tickCallback (node.js:192:40)
----------------------------------------
    at EventEmitter.on
    at ServerResponse.assignSocket (http.js:786:10)
    at HTTPParser.onIncoming (http.js:1454:11)
    at HTTPParser.onHeadersComplete (http.js:102:31)
    at Socket.ondata (http.js:1387:22)
    at TCP.onread (net.js:354:27)
Uncaught undefined

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick

@Kami
Copy link
Author

Kami commented Jan 18, 2012

Sorry for a wrong bug report, it was a bug in our code.

We had a function which incorrectly wrapped a function passed to addListener which meant socket.removeListener('close', onServerResponse) in http.js, didn't actually remove the close listener.

@Kami Kami closed this as completed Jan 18, 2012
@vulkanr
Copy link

vulkanr commented Jan 23, 2012

its actually happened to me too. i tracked it down to the "keep alive" connection. i think there's something wrong in commit dd9593c. it does not take into account keep-alive connections and the "on close" event listener keeps registering until it hits the limit of listeners (11) and then fails.
the exception is thrown when the actual socket closes and the "close" event fired (but listener failed to subscribe...)

@rstuven
Copy link

rstuven commented May 30, 2012

I had this issue too. This comment gave me a hint for my case: the cause was an interaction with long-stack-traces module.

@CrabDude
Copy link

CrabDude commented Nov 9, 2012

LST-related resolution: See tlrobinson/long-stack-traces#9 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants