brillout / react-streaming

React Streaming. Full-fledged & Easy.
MIT License
216 stars 14 forks source link

Cannot call write after a stream was destroyed #20

Closed JiangWeixian closed 1 year ago

JiangWeixian commented 1 year ago

Will throw this error:

Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
    at __node_internal_captureLargerStackTrace (node:internal/errors:490:5)
    at new NodeError (node:internal/errors:399:5)
    at write_ (node:_http_outgoing:880:11)
    at ServerResponse.write (node:_http_outgoing:831:15)
}

Maybe a fix for this:

convert this

writableFromUser.write(chunk, encoding, callback)

into this

if (!writableFromUser.destroyed) {
  writableFromUser.write(chunk, encoding, callback)
}

If this is a bug, I like to open PR for this issue

brillout commented 1 year ago

👍 PR welcome.