Skip to content

mux-demux tries to write to stream after it's closed #7

Raynos opened this Issue Aug 9, 2012 · 6 comments

2 participants

Raynos commented Aug 9, 2012

After a stream is closed I get a write message incoming and this throws a stream is not writable Error.

This could be a race condition with buffering data whilst opening and closing connections or a bug in my code.

As always running seaport-proxy service demo and repeatedly opening and closing connections get's this error to bubble up.

mux-demux would be a lot more friendly if it just drops connections that are in a corrupted state rather then throwing an exception and killing my server. Calling stream.end() instead of throw new Error("fix your race conditions") would be nicer.

function createStream(id, meta, opts) {
    console.log("[CREATE] creatingStream", id)
    var s = es.through(function (data) {
      if(!this.writable) {
        console.log("[NOT WRITABLE]", id, meta, opts)
        throw new Error('stream is not writable')
      md.emit('data', [, 'data', data])
    }, function () {
      md.emit('data', [, 'end'])
      if (this.readable && !opts.allowHalfOpen && !this.ended) {

If it's not writable that means that it's already emitted end, close or error.
(yeah, there are too many ways a stream can end, but that will change in 0.9)

can you post a stacktrace?

if you are using pipe to write to the stream, it will check whether it is writable,
and drop the write if it isn't.

does this crash on the server or on the browser?

Raynos commented Aug 9, 2012

@dominictarr it crashes on the server.

I think I need a flag to change all the thrown errors for logging and closing streams as it's just not worth crashing my server for


@raynos hey we fixed this right? we probably just talked about it in IRC and forgot about closing the issue.

Raynos commented Oct 26, 2012

im sure this is fixed too.


cool, closing.

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.