40036: Write to a closed stream
stream_closedA write was refused because the stream or writer was already closed, so nothing was published for that write. A closed stream or writer accepts no more writes.
What you should do
Make every write before you close the stream or writer. To continue writing after a close, open a new writer or a new stream on the same message. Make the write there. The closed stream or writer does not reopen.
Why it happens
Closing a stream or writer waits for the writes already made to apply. Any write made after the close was called is refused with this error.
This can happen when a callback fires late or code keeps a reference to the closed writer. The write is refused instead of being dropped silently.
What you'll see
The error is reported with code 40036 and HTTP status 400. In the Ably AI Transport JavaScript SDK, the message is unable to write event; the writer is closed.