From 2c9fcd7c1402a48165f4bfab8798ed6ed98b2f84 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sun, 19 Sep 2021 20:00:06 +0200 Subject: [PATCH] rpc/dataconn: always close send stream returned from Sender.Send() discovered while debugging #457 --- rpc/dataconn/dataconn_server.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/rpc/dataconn/dataconn_server.go b/rpc/dataconn/dataconn_server.go index 93bf0fd..dee14e0 100644 --- a/rpc/dataconn/dataconn_server.go +++ b/rpc/dataconn/dataconn_server.go @@ -172,6 +172,15 @@ func (s *Server) serveConnRequest(ctx context.Context, endpoint string, c *strea return } res, sendStream, handlerErr = s.h.Send(ctx, &req) // SHADOWING + // ensure that we always close the sendStream + if sendStream != nil { + defer func() { + err := sendStream.Close() + if err != nil { + s.log.WithError(err).Error("cannot close send stream") + } + }() + } case EndpointRecv: var req pdu.ReceiveReq if err := proto.Unmarshal(reqStructured, &req); err != nil { @@ -239,12 +248,9 @@ func (s *Server) serveConnRequest(ctx context.Context, endpoint string, c *strea if sendStream != nil { err := c.SendStream(ctx, sendStream, ZFSStream) - closeErr := sendStream.Close() - if closeErr != nil { - s.log.WithError(closeErr).Error("cannot close send stream") - } if err != nil { s.log.WithError(err).Error("cannot write send stream") } + // sendStream.Close() done via defer above } }