Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@isaacs
Created December 15, 2012 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaacs/4299932 to your computer and use it in GitHub Desktop.
Save isaacs/4299932 to your computer and use it in GitHub Desktop.
diff --git a/lib/net.js b/lib/net.js
index d0a2c5a..42c2109 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -595,9 +595,12 @@ Socket.prototype._write = function(dataEncoding, cb) {
return this._destroy(errnoException(errno, 'write'), cb);
writeReq.oncomplete = afterWrite;
- writeReq.cb = cb;
-
this._bytesDispatched += writeReq.bytes;
+
+ if (this._handle.writeQueueSize === 0)
+ cb();
+ else
+ writeReq.cb = cb;
};
@@ -640,7 +643,8 @@ function afterWrite(status, handle, req) {
if (self !== process.stderr && self !== process.stdout)
debug('afterWrite call cb');
- req.cb.call(self);
+ if (req.cb)
+ req.cb.call(self);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment