[PATCH] Fix node.js connection.send() issue

29 views
Skip to first unread message

Felix Geisendörfer

unread,
Aug 18, 2009, 6:28:06 PM8/18/09
to nodejs
Hey Ryan,

We have our node.js server monitored by monit, however it seems monit
is pretty agressive / quick about closing its connection and thus
we've gotten into a loop of errors like this:

at #<a ServerResponse>.flush
at #<a ServerResponse>.sendBody
at [object Object].json
at [object Object].[anonymous]
at [object Object].[anonymous]
at [object Object].[anonymous]
http.js:353: Socket is not open for writing
connection.send(out, out.encoding);
^

Below is a patch that basically cause flushMessageQueue to check the
connection state for each item in the queue rather than just a single
time in the beginning.

From d33d17dc909f20db6296ac7a1f6428b90c105243 Mon Sep 17 00:00:00 2001
From: Kevin van Zonneveld <ke...@vanzonneveld.net>
Date: Wed, 19 Aug 2009 00:07:53 +0200
Subject: [PATCH] Buggy connections could crash node.js. Now check
connection before sending data every time

---
src/http.js | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/http.js b/src/http.js
index 568d0a7..625fa6c 100644
--- a/src/http.js
+++ b/src/http.js
@@ -341,15 +341,15 @@ function createIncomingMessageStream
(connection, incoming_listener) {
/* Returns true if the message queue is finished and the connection
* should be closed. */
function flushMessageQueue (connection, queue) {
- if (connection.readyState !== "open" && connection.readyState !==
"writeOnly") {
- return false;
- }

while (queue[0]) {
var message = queue[0];

while (message.output.length > 0) {
var out = message.output.shift();
+ if (connection.readyState !== "open" && connection.readyState !
== "writeOnly") {
+ return false;
+ }
connection.send(out, out.encoding);
}

--
1.6.0.4

-- Felix Geisendörfer aka the_undefined

ryan dahl

unread,
Aug 21, 2009, 12:08:45 PM8/21/09
to nod...@googlegroups.com
Thanks. A test would be great - for now I'll just apply this patch
(almost, i made a one line change)
8489bdbaeb07b18a736a438719adc8837c1908a0

Felix Geisendörfer

unread,
Aug 21, 2009, 6:32:46 PM8/21/09
to nodejs
Hey Ryan,

Thanks a lot for the fix. I did try to come up with a test case but
couldn't get one to consistently work right away. I'll try harder next
time.

-- Felix Geisendörfer
Reply all
Reply to author
Forward
0 new messages