Skip to content

node js Stream must implement destroy #79

dominictarr opened this Issue Jul 6, 2012 · 9 comments

4 participants


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

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.


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.

it should be helpful.

SockJS member
majek commented Jul 6, 2012

Yes, destroy is implemented already:

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

Closes the underlying file descriptor. Stream will not emit any more events.

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

and here in net

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


my pull request has been merged, and the documentation is now corrected.

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 commented Oct 4, 2012

Any updates on this?


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


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


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.