telamon / hypercore-substream

Independent virtual streams through a hypercore-protocol stream
MIT License
7 stars 0 forks source link

bug: Flush substreams on mainStream.end() #1

Open telamon opened 5 years ago

telamon commented 5 years ago

There's a warning message

Warn: mainstream closed while substream was initializing or active

It is logged whenever a substream has the rug pulled from under it's feet before it had time to flush it's buffers. If the real/main stream was destroyed, there's no flushing occuring and substreams are destroyed as well.

But if the main-stream tries to do a clean exit through stream.end(null, cb), the end calback should be deferred until all substreams are flushed and closed.

This will enable us to do a graceful exit without warnings.

telamon commented 5 years ago

To be verified, mafintosh suggested that I should use streamx module instead of the multiplexing stream implemented in this module.