diff --git a/src/http.js b/src/http.js index b59896a20b6c1f..abf489095fdfe9 100644 --- a/src/http.js +++ b/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); }