diff --git a/lib/net_uv.js b/lib/net_uv.js index 33114d69bae..4c11be2ecff 100644 --- a/lib/net_uv.js +++ b/lib/net_uv.js @@ -171,6 +171,7 @@ Socket.prototype.end = function(data, encoding) { this.writable = false; this._flags |= FLAG_SHUTDOWNQUED; } + if (!this.writable) return; this.writable = false; @@ -182,8 +183,16 @@ Socket.prototype.end = function(data, encoding) { } else { this._flags |= FLAG_SHUTDOWN; var shutdownReq = this._handle.shutdown(); + + if (!shutdownReq) { + this.destroy(errnoException(errno, 'shutdown')); + return false; + } + shutdownReq.oncomplete = afterShutdown; } + + return true; };