Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Paused stream keeps node alive #6653

Closed
piscisaureus opened this issue Dec 6, 2013 · 10 comments
Closed

Paused stream keeps node alive #6653

piscisaureus opened this issue Dec 6, 2013 · 10 comments
Labels

Comments

@piscisaureus
Copy link

Test code:

var conn = require('net').connect(80, 'www.google.com');
// Should not be necessary but just to be sure:
conn.pause();

Both node v0.10.x and master hang and don't exit.

@isaacs, any idea? The libuv handle is clearly reading; is node secretly reading under the hood?

@indutny
Copy link
Member

indutny commented Dec 6, 2013

Why should it exit?

@piscisaureus
Copy link
Author

@indutny Because no more events will happen. Like this:

process.stdin.resume();
process.stdin.pause();

@trevnorris
Copy link

This is a good point. The only way it could be resumed is if another asynchronous event is fired after. Which would also keep the process alive. So there should be no need to keep the process open on pause().

@tjfontaine
Copy link

see also #6305, also for some reason ._handle.readStop() isn't being triggered here, I would have presumed we would have hit it when hwm was reached.

@tjfontaine
Copy link

ok, so in this case we're hanging because there's no data to be read from the socket since http doesn't respond until you actually GET something, if you switch to towel.blinkenlights.nl:23 you'll eventually hit hwm and dump out. So, with that in mind I have a semi working patch, that subscribes net.Socket to the pause handler and readStops it unfortunately breaks 2 tests

diff --git a/lib/net.js b/lib/net.js
index 93d942a..000bad4 100644
--- a/lib/net.js
+++ b/lib/net.js
@@ -167,6 +167,7 @@ function Socket(options) {
   // shut down the socket when we're finished with it.
   this.on('finish', onSocketFinish);
   this.on('_socketEnd', onSocketEnd);
+  this.on('pause', onSocketPause);

   initSocketHandle(this);

@@ -220,6 +221,13 @@ function onSocketFinish() {
 }


+function onSocketPause() {
+  debug('onSocketPause');
+  if (this._handle && this._handle.readStop)
+    this._handle.readStop();
+}
+
+
 function afterShutdown(status, handle, req) {
   var self = handle.owner;

@jasnell
Copy link
Member

jasnell commented May 28, 2015

@joyent/node-coreteam @piscisaureus ... the hang still happens in v0.10 but not in v0.12 or io.js... do we care? Is there a fix we can / should backport to v0.10?

@piscisaureus
Copy link
Author

This is a streams question - @cjihrig or @chrisdickinson may know the answer

@chrisdickinson
Copy link

Yep, looks like I patched it to solve #8200: 4ef2a5a. Downside is that it adds a new API (isPaused.)

@jasnell
Copy link
Member

jasnell commented May 28, 2015

Hmm.. I'm inclined just to close then and leave the v0.10 behavior as is.

@jasnell
Copy link
Member

jasnell commented Jun 3, 2015

Closing. This leaves the existing v0.10 behavior alone. Can reopen if folks feel it's necessary to fix this in v0.10

@jasnell jasnell closed this as completed Jun 3, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants