thread 'main' panicked at 'Unfold must not be polled after it returned `Poll::Ready(None)`', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-util-0.3.13/src/stream/unfold.rs:115:21
Once you get Poll::Ready(None) you are not supposed to keep calling it (see futures::stream::Stream - Rust for a description of return values). At this point, the stream should be considered exhausted.
You can fuse a stream, which will allow poll_next() to be called even after the end of the stream (you'll just keep getting None back instead of panicking).
Would it not make sense to terminate the loop when you get None back?
while let Some(item) = stream.next().await {
...
}
In the above, once next() returns None, it will stop iterating through the loop. This is because None means that the stream is done. The panic you ran into indicates that you called next again after it has returned None.
It's unclear from your code how the Unfold stream relates to the TCP socket, but when a Stream returns None, then yes, the Stream is closed and will never produce more items.