From f9aca39cafd87145a74a5a4b63d259857b9ee761 Mon Sep 17 00:00:00 2001 From: Ruslan Tushov Date: Fri, 25 Dec 2020 16:03:46 +0300 Subject: [PATCH] Buffered stream for chainxchg response --- chain/exchange/server.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/chain/exchange/server.go b/chain/exchange/server.go index 31eec46cafe..7c1624e579a 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())