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

node crashes when Stream.on('readable', ...) on Duplex #5146

Closed
alexlamsl opened this issue Mar 26, 2013 · 7 comments
Closed

node crashes when Stream.on('readable', ...) on Duplex #5146

alexlamsl opened this issue Mar 26, 2013 · 7 comments

Comments

@alexlamsl
Copy link

A simple way to reproduce this issue:

~$ node
> process.stdout instanceof require('stream').Duplex
true
> process.stdout.on('readable', function() {console.log('stdout')})

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: This socket is closed.
    at WriteStream.Socket._write (net.js:618:19)
    at doWrite (_stream_writable.js:211:10)
    at writeOrBuffer (_stream_writable.js:201:5)
    at WriteStream.Writable.write (_stream_writable.js:172:11)
    at WriteStream.Socket.write (net.js:596:40)
    at finish (repl.js:291:27)
    at repl.js:251:15
    at REPLServer.self.eval (repl.js:122:7)
    at Interface. (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)

~$

Note that node crashes - and this is reproducible for normal mode as well as shell mode.

@isaacs
Copy link

isaacs commented Mar 26, 2013

Ah, that's weird.

Note: process.stdout is not actually "readable", so the bug here is that it even tries to read from it.

@alexlamsl
Copy link
Author

I agree whole-heartedly - except this is a Duplex, which makes process.stdout instanceof require('stream').Readable === true

Or have I mistaken about how Duplex should behave?

@isaacs
Copy link

isaacs commented Mar 26, 2013

Well, it's a Socket, which is a child of Duplex, because Sockets are sometimes readable and sometimes writable and sometimes both or neither. But just because it's an instanceof Readable doesn't necessarily mean that you can read from it. After all,

> process.stdout.readable
false

@isaacs
Copy link

isaacs commented Mar 26, 2013

I'm not able to reproduce this on latest v0.10. Can you? I'm guessing it got fixed somehow?

@isaacs isaacs closed this as completed Mar 26, 2013
@alexlamsl
Copy link
Author

I am on 0.10.1 (and Windows):

C:\nodejs>node
> process.version
'v0.10.1'
> process.stdout instanceof require('stream').Readable
true
> process.stdout.readable
false
>

So you are saying I should use stream.readable instead of instanceof?

@TooTallNate
Copy link

yes

@alexlamsl
Copy link
Author

Thanks for the clarification :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants