Skip to content

node js Stream must implement destroy #79

Closed
dominictarr opened this Issue Jul 6, 2012 · 9 comments

4 participants

@dominictarr

Since the server side of sockjs is a stream, it needs to implement destroy
as destroy is called by pipe in some cases.

https://github.com/joyent/node/blob/master/lib/stream.js#L74

It should basically do what close does, but without asking.
It should just terminate any connection... which will mean calling destroy
on whatever underling stream is currently in use.

@dominictarr

oh, oops, I see do implement destroy.
but not correctly.
you should not removeAllListeners

destroy should set this.writable = false
dispose of any resources, and then emit 'close'

indeed, pipe, will listen on 'close' and calling this.removeAllListeners() will leave pipe hanging.

I am working on a guide for correct streams.
https://github.com/dominictarr/stream-spec/blob/master/stream_spec.md

it should be helpful.

@majek
SockJS member
majek commented Jul 6, 2012

Yes, destroy is implemented already:
https://github.com/sockjs/sockjs-node/blob/dev/src/transport.coffee#L47

Correct me if I'm wrong about removeAllListeners but node docs say:

http://nodejs.org/api/stream.html#stream_stream_destroy

stream.destroy()#
Closes the underlying file descriptor. Stream will not emit any more events.
@dominictarr

oh, thats a mistake in the documentation. I'll look into getting that fixed.

it should be "no more 'data', 'end', or 'drain' events will be emitted"

look here, in fs

https://github.com/joyent/node/blob/master/lib/fs.js#L1359-1383

and here in net

https://github.com/joyent/node/blob/master/lib/net.js#L322-374

destroy causes either 'close' or 'error' to be emmited.

@dominictarr

my pull request has been merged, and the documentation is now corrected.
http://nodejs.org/api/stream.html#stream_event_close

@majek
SockJS member
majek commented Jul 12, 2012

Great! Destroy definitely should be modified to adhere to the new docs. Now the ball is on my side.

@majek majek was assigned Jul 12, 2012
@theyak
theyak commented Oct 4, 2012

Any updates on this?

@brycekahle

This applied to old streams, but now we should be using stream.Duplex

@brycekahle

@dominictarr Do you think my change is sufficient to fix this issue?

@brycekahle

I think this is fixed by my commit. Reopen if you think otherwise.

@brycekahle brycekahle closed this Oct 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.