Browse files

Buggy connections could crash node.js. Now check connection before se…

…nding data every time

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
  • Loading branch information...
1 parent ed3602d commit 8489bdbaeb07b18a736a438719adc8837c1908a0 @kvz kvz committed with ry Aug 21, 2009
Showing with 3 additions and 4 deletions.
  1. +3 −4 src/http.js
@@ -341,14 +341,13 @@ 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) {
+ if (connection.readyState !== "open" && connection.readyState !== "writeOnly") {
+ return false;
+ }
var out = message.output.shift();
connection.send(out, out.encoding);

0 comments on commit 8489bdb

Please sign in to comment.