When a stream is closed gracefully, it's status goes from 'open' to 'closing' then to either 'closed', 'aborted' or 'reset'.
While it's 'closing' we should still try to send any queued data, this can be aborted by calling .abort on the stream or by the signal passed to .close firing the 'abort' event.
This change makes the tests added in https://github.com/libp2p/js-libp2p/pull/2398 pass, in particular the one where we use it-byte-stream and write data larger than the send capacity. When this happens we wait for the remote to signal to accept more data, during which time the stream is closed gracefully and the data ends up being truncated as we stop sending when this.status is no longer 'open'.
When a stream is closed gracefully, it's status goes from
'open'
to'closing'
then to either'closed'
,'aborted'
or'reset'
.While it's
'closing'
we should still try to send any queued data, this can be aborted by calling.abort
on the stream or by the signal passed to.close
firing the'abort'
event.This change makes the tests added in https://github.com/libp2p/js-libp2p/pull/2398 pass, in particular the one where we use
it-byte-stream
and write data larger than the send capacity. When this happens we wait for the remote to signal to accept more data, during which time the stream is closed gracefully and the data ends up being truncated as we stop sending whenthis.status
is no longer'open'
.