Skip to content

Instantly share code, notes, and snippets.

@indutny

indutny/1.diff Secret

Created June 10, 2014 22:34
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 indutny/8909b18665758fa69835 to your computer and use it in GitHub Desktop.
Save indutny/8909b18665758fa69835 to your computer and use it in GitHub Desktop.
diff --git a/lib/_http_server.js b/lib/_http_server.js
index 44ebaa6..72e5b62 100644
--- a/lib/_http_server.js
+++ b/lib/_http_server.js
@@ -475,7 +475,7 @@ function connectionListener(socket) {
// if the user never called req.read(), and didn't pipe() or
// .resume() or .on('data'), then we call req._dump() so that the
// bytes will be pulled off the wire.
- if (!req._consuming)
+ if (!req._consuming && !req._readableState.resumeScheduled)
req._dump();
res.detachSocket(socket);
diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js
index 192b0a9..90ea53e 100644
--- a/lib/_stream_readable.js
+++ b/lib/_stream_readable.js
@@ -701,10 +701,6 @@ Readable.prototype.resume = function() {
if (!state.flowing) {
debug('resume');
state.flowing = true;
- if (!state.reading) {
- debug('resume read 0');
- this.read(0);
- }
resume(this, state);
}
return this;
@@ -720,6 +716,11 @@ function resume(stream, state) {
}
function resume_(stream, state) {
+ if (!state.reading) {
+ debug('resume read 0');
+ stream.read(0);
+ }
+
state.resumeScheduled = false;
stream.emit('resume');
flow(stream);
diff --git a/test/disabled/test-http-abort-stream-end.js b/test/disabled/test-http-abort-stream-end.js
new file mode 100644
index 0000000..e2ffa45
--- /dev/null
+++ b/test/disabled/test-http-abort-stream-end.js
@@ -0,0 +1,61 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var common = require('../common');
+var assert = require('assert');
+
+var http = require('http');
+
+var maxSize = 1024;
+var size = 0;
+
+var s = http.createServer(function(req, res) {
+ this.close();
+
+ res.writeHead(200, {'Content-Type': 'text/plain'});
+ for (var i = 0; i < maxSize; i++) {
+ res.write('x' + i);
+ }
+ res.end();
+});
+
+var aborted = false;
+s.listen(common.PORT, function() {
+ var req = http.get('http://localhost:' + common.PORT, function(res) {
+ res.on('data', function(chunk) {
+ size += chunk.length;
+ assert(!aborted, 'got data after abort');
+ if (size > maxSize) {
+ aborted = true;
+ req.abort();
+ size = maxSize;
+ }
+ });
+ });
+
+ req.end();
+});
+
+process.on('exit', function() {
+ assert(aborted);
+ assert.equal(size, maxSize);
+ console.log('ok');
+});
diff --git a/test/disabled/test-stdout-close-unref.js b/test/disabled/test-stdout-close-unref.js
new file mode 100644
index 0000000..42f3997
--- /dev/null
+++ b/test/disabled/test-stdout-close-unref.js
@@ -0,0 +1,24 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+process.stdin.resume();
+process.stdin._handle.close();
+process.stdin._handle.unref(); // Should not segfault.
diff --git a/test/simple/test-http-abort-stream-end.js b/test/simple/test-http-abort-stream-end.js
deleted file mode 100644
index e2ffa45..0000000
--- a/test/simple/test-http-abort-stream-end.js
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-var common = require('../common');
-var assert = require('assert');
-
-var http = require('http');
-
-var maxSize = 1024;
-var size = 0;
-
-var s = http.createServer(function(req, res) {
- this.close();
-
- res.writeHead(200, {'Content-Type': 'text/plain'});
- for (var i = 0; i < maxSize; i++) {
- res.write('x' + i);
- }
- res.end();
-});
-
-var aborted = false;
-s.listen(common.PORT, function() {
- var req = http.get('http://localhost:' + common.PORT, function(res) {
- res.on('data', function(chunk) {
- size += chunk.length;
- assert(!aborted, 'got data after abort');
- if (size > maxSize) {
- aborted = true;
- req.abort();
- size = maxSize;
- }
- });
- });
-
- req.end();
-});
-
-process.on('exit', function() {
- assert(aborted);
- assert.equal(size, maxSize);
- console.log('ok');
-});
diff --git a/test/simple/test-stdout-close-unref.js b/test/simple/test-stdout-close-unref.js
deleted file mode 100644
index 42f3997..0000000
--- a/test/simple/test-stdout-close-unref.js
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright Joyent, Inc. and other Node contributors.
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to permit
-// persons to whom the Software is furnished to do so, subject to the
-// following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
-// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
-// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
-// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
-// USE OR OTHER DEALINGS IN THE SOFTWARE.
-
-process.stdin.resume();
-process.stdin._handle.close();
-process.stdin._handle.unref(); // Should not segfault.
diff --git a/test/simple/test-stream-readable-data-sync-race.js b/test/simple/test-stream-readable-data-sync-race.js
new file mode 100644
index 0000000..5bbfcc8
--- /dev/null
+++ b/test/simple/test-stream-readable-data-sync-race.js
@@ -0,0 +1,41 @@
+// Copyright Joyent, Inc. and other Node contributors.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to permit
+// persons to whom the Software is furnished to do so, subject to the
+// following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
+// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+// USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+var common = require('../common');
+var assert = require('assert');
+
+var Readable = require('stream').Readable;
+
+var r = new Readable();
+var errors = 0;
+
+// Setting `data` listener should not trigger `_read()` calls before we will
+// set the `error` listener below
+r.on('data', function() {
+});
+
+r.on('error', function() {
+ errors++;
+});
+
+process.on('exit', function() {
+ assert.equal(errors, 1);
+});
diff --git a/test/simple/test-stream2-readable-legacy-drain.js b/test/simple/test-stream2-readable-legacy-drain.js
index 675da8e..117e253 100644
--- a/test/simple/test-stream2-readable-legacy-drain.js
+++ b/test/simple/test-stream2-readable-legacy-drain.js
@@ -49,7 +49,7 @@ w.write = function(c) {
};
function drain() {
- assert(buffered <= 2);
+ assert(buffered <= 3);
buffered = 0;
w.emit('drain');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment