summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2013-06-04 23:43:29 -0700
committerisaacs <i@izs.me>2013-06-05 08:06:35 -0700
commite0519ace315c7ce14278d5eaab8d1d72a0a0a054 (patch)
tree09aa41db21669ef9bcf4bcf491cd40a7aea1af04 /lib
parent6ada73383cfc4b5b1e85ae96412a23c330433cf5 (diff)
downloadandroid-node-v8-e0519ace315c7ce14278d5eaab8d1d72a0a0a054.tar.gz
android-node-v8-e0519ace315c7ce14278d5eaab8d1d72a0a0a054.tar.bz2
android-node-v8-e0519ace315c7ce14278d5eaab8d1d72a0a0a054.zip
net: Destroy when not readable and not writable
This is only relevant for CentOS 6.3 using kernel version 2.6.32. On other linuxes and darwin, the `read` call gets an ECONNRESET in that case. On sunos, the `write` call fails with EPIPE. However, old CentOS will occasionally send an EOF instead of a ECONNRESET or EPIPE when the client has been destroyed abruptly. Make sure we don't keep trying to write or read more in that case. Fixes #5504 However, there is still the question of what libuv should do when it gets an EOF. Apparently in this case, it will continue trying to read, which is almost certainly the wrong thing to do. That should be fixed in libuv, even though this works around the issue.
Diffstat (limited to 'lib')
-rw-r--r--lib/net.js20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/net.js b/lib/net.js
index 7f6f306b84..620fd29a32 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -249,9 +249,11 @@ function onSocketEnd() {
this._readableState.ended = true;
if (this._readableState.endEmitted) {
this.readable = false;
+ maybeDestroy(this);
} else {
this.once('end', function() {
this.readable = false;
+ maybeDestroy(this);
});
this.read(0);
}
@@ -399,10 +401,22 @@ Socket.prototype.end = function(data, encoding) {
// just in case we're waiting for an EOF.
if (this.readable && !this._readableState.endEmitted)
this.read(0);
- return;
+ else
+ maybeDestroy(this);
};
+// Call whenever we set writable=false or readable=false
+function maybeDestroy(socket) {
+ if (!socket.readable &&
+ !socket.writable &&
+ !socket.destroyed &&
+ !socket._connecting) {
+ socket.destroy();
+ }
+}
+
+
Socket.prototype.destroySoon = function() {
if (this.writable)
this.end();
@@ -521,8 +535,10 @@ function onread(buffer, offset, length) {
} else if (process._errno == 'EOF') {
debug('EOF');
- if (self._readableState.length === 0)
+ if (self._readableState.length === 0) {
self.readable = false;
+ maybeDestroy(self);
+ }
if (self.onend) self.once('end', self.onend);