diff --git a/chain/exchange/server.go b/chain/exchange/server.go index 31eec46ca..7c1624e57 100644 --- a/chain/exchange/server.go +++ b/chain/exchange/server.go @@ -56,7 +56,11 @@ func (s *server) HandleStream(stream inet.Stream) { } _ = stream.SetDeadline(time.Now().Add(WriteResDeadline)) - if err := cborutil.WriteCborRPC(stream, resp); err != nil { + buffered := bufio.NewWriter(stream) + if err = cborutil.WriteCborRPC(buffered, resp); err == nil { + err = buffered.Flush() + } + if err != nil { _ = stream.SetDeadline(time.Time{}) log.Warnw("failed to write back response for handle stream", "err", err, "peer", stream.Conn().RemotePeer())