summaryrefslogtreecommitdiff
path: root/lib/net.js
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2016-10-12 20:39:37 +0000
committerFedor Indutny <fedor@indutny.com>2016-10-14 13:38:56 +0000
commit31196eaa936e38a1a2bc189f4fcd5f633d814c13 (patch)
tree4fc979d0d8cd465b9e8e08f78ac00e20fee913b9 /lib/net.js
parent0ed633801671af95c0dad1d1320b230ecbef6483 (diff)
downloadandroid-node-v8-31196eaa936e38a1a2bc189f4fcd5f633d814c13.tar.gz
android-node-v8-31196eaa936e38a1a2bc189f4fcd5f633d814c13.tar.bz2
android-node-v8-31196eaa936e38a1a2bc189f4fcd5f633d814c13.zip
net: fix ambiguity in EOF handling
`end` MUST always be emitted **before** `close`. However, if a handle will invoke `uv_close_cb` immediately, or in the same JS tick - `close` may be emitted first. PR-URL: https://github.com/nodejs/node/pull/9066 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
Diffstat (limited to 'lib/net.js')
-rw-r--r--lib/net.js8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/net.js b/lib/net.js
index 3944b9627c..31f1c31bf3 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -574,14 +574,16 @@ function onread(nread, buffer) {
debug('EOF');
+ // push a null to signal the end of data.
+ // Do it before `maybeDestroy` for correct order of events:
+ // `end` -> `close`
+ self.push(null);
+
if (self._readableState.length === 0) {
self.readable = false;
maybeDestroy(self);
}
- // push a null to signal the end of data.
- self.push(null);
-
// internal end event so that we know that the actual socket
// is no longer readable, and we can start the shutdown
// procedure. No need to wait for all the data to be consumed.