From 8da02467024b89b5e86026027281d9dc51ebc0f9 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Wed, 8 Jul 2020 13:03:03 -0700 Subject: [PATCH] Close buf writer in event of an error (#6523) * Close buf writer in event of an error * Merge refs/heads/master into close-bufwriter * Merge refs/heads/master into close-bufwriter --- beacon-chain/p2p/encoder/ssz.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/beacon-chain/p2p/encoder/ssz.go b/beacon-chain/p2p/encoder/ssz.go index 7846f7328..5a0ac1cdc 100644 --- a/beacon-chain/p2p/encoder/ssz.go +++ b/beacon-chain/p2p/encoder/ssz.go @@ -151,6 +151,10 @@ func writeSnappyBuffer(w io.Writer, b []byte) (int, error) { defer bufWriterPool.Put(bufWriter) num, err := bufWriter.Write(b) if err != nil { + // Close buf writer in the event of an error. + if err := bufWriter.Close(); err != nil { + return 0, err + } return 0, err } return num, bufWriter.Close()