Question

I have a code like the following. It works correctly at the first time. After that I get a write after end. I understand what the problem is, but somehow I don't understand how to do it correctly. I so far tried unpiping and using Half Open Connections. I feel out of ideas and out of examples.

server = require('net').createServer (input) ->
  input
    .pipe(someTransformObjectStream)
    .pipe(foo)
    .pipe(bar)

Stack Trace:

events.js:72
    throw er; // Unhandled 'error' event

Error: write after end
  at writeAfterEnd (_stream_writable.js:130:12)
  at someTransformObjectStream.Writable.write (_stream_writable.js:178:5)
  at write (_stream_readable.js:583:24)
  at flow (_stream_readable.js:592:7)
  at Socket.pipeOnReadable (_stream_readable.js:624:5)
  at Socket.EventEmitter.emit (events.js:92:17)
  at emitReadable_ (_stream_readable.js:408:10)
  at emitReadable (_stream_readable.js:404:5)
  at readableAddChunk (_stream_readable.js:165:9)
  at Socket.Readable.push (_stream_rea
Was it helpful?

Solution

The problem is that you reuse the same transform for a new connection, but is already ended. You need to create new transforms for every connection

server = require('net').createServer (input) ->
  input
    .pipe(createSomeTransformObjectStream())
    .pipe(createFoo())
    .pipe(createBar())
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top