From 0662d18f50149986d9de40cfa9c8300cb07c0b88 Mon Sep 17 00:00:00 2001 From: mscdex Date: Tue, 23 Jul 2013 09:08:35 -0400 Subject: [PATCH] Connection: guard possible direct socket write --- lib/Connection.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/Connection.js b/lib/Connection.js index 5e8c6b1..c7a94b3 100644 --- a/lib/Connection.js +++ b/lib/Connection.js @@ -1079,7 +1079,7 @@ Connection.prototype.__defineGetter__('seq', function() { }); Connection.prototype._resUntagged = function(info) { - var type = info.type, i, len, box, attrs; + var type = info.type, i, len, box, attrs, key; if (type === 'bye') this._sock.end(); @@ -1148,7 +1148,7 @@ Connection.prototype._resUntagged = function(info) { if (!this._box) this._createCurrentBox(); - var key = info.textCode.key.toUpperCase(); + key = info.textCode.key.toUpperCase(); if (key === 'UIDVALIDITY') this._box.uidvalidity = info.textCode.val; @@ -1238,7 +1238,7 @@ Connection.prototype._resUntagged = function(info) { var msg = this._curReq.fetchCache[info.num], keys = Object.keys(info.text), keyslen = keys.length, - toget, msgEmitter, j, key; + toget, msgEmitter, j; if (msg === undefined) { // simple case -- no bodies were streamed @@ -1564,7 +1564,10 @@ Connection.prototype._enqueue = function(fullcmd, promote, cb) { // defer until next tick for requests like APPEND and FETCH where access to // the request object is needed immediately after enqueueing process.nextTick(function() { self._processQueue(); }); - } else if (this._curReq && this._curReq.type === 'IDLE') { + } else if (this._curReq + && this._curReq.type === 'IDLE' + && this._sock + && this._sock.writable) { this._idle.enabled = false; this.debug && this.debug('=> DONE'); this._sock.write('DONE' + CRLF);