From 12fcd27cd412f33eee3c7f0def93f14c6339f1fa Mon Sep 17 00:00:00 2001 From: godeamon Date: Tue, 21 Nov 2023 20:36:13 +0800 Subject: [PATCH 1/3] add ctx canceled err check --- internal/net/message_manager.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/net/message_manager.go b/internal/net/message_manager.go index 7908be2b..e640d8e3 100644 --- a/internal/net/message_manager.go +++ b/internal/net/message_manager.go @@ -295,8 +295,10 @@ func (ms *peerMessageSender) SendRequest(ctx context.Context, pmes *pb.Message) mes := new(pb.Message) if err := ms.ctxReadMsg(ctx, mes); err != nil { - _ = ms.s.Reset() - ms.s = nil + if err != context.Canceled { + _ = ms.s.Reset() + ms.s = nil + } if retry { logger.Debugw("error reading message", "error", err) From 097cb9ab4e3a962a52023ec139ab116f7cba724c Mon Sep 17 00:00:00 2001 From: godeamon Date: Wed, 22 Nov 2023 17:43:15 +0800 Subject: [PATCH 2/3] return canceled err not retry --- internal/net/message_manager.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/net/message_manager.go b/internal/net/message_manager.go index e640d8e3..7e9a00a3 100644 --- a/internal/net/message_manager.go +++ b/internal/net/message_manager.go @@ -295,11 +295,11 @@ func (ms *peerMessageSender) SendRequest(ctx context.Context, pmes *pb.Message) mes := new(pb.Message) if err := ms.ctxReadMsg(ctx, mes); err != nil { - if err != context.Canceled { - _ = ms.s.Reset() - ms.s = nil + if err == context.Canceled { + return nil, err } - + _ = ms.s.Reset() + ms.s = nil if retry { logger.Debugw("error reading message", "error", err) return nil, err From ae0987ef008585b248237a7b2aabc39dde003765 Mon Sep 17 00:00:00 2001 From: godeamon Date: Fri, 24 Nov 2023 21:29:29 +0800 Subject: [PATCH 3/3] reset stream and return err when ctx canceled --- internal/net/message_manager.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/net/message_manager.go b/internal/net/message_manager.go index 7e9a00a3..c26b5eef 100644 --- a/internal/net/message_manager.go +++ b/internal/net/message_manager.go @@ -295,11 +295,12 @@ func (ms *peerMessageSender) SendRequest(ctx context.Context, pmes *pb.Message) mes := new(pb.Message) if err := ms.ctxReadMsg(ctx, mes); err != nil { + _ = ms.s.Reset() + ms.s = nil if err == context.Canceled { + // retry would be same error return nil, err } - _ = ms.s.Reset() - ms.s = nil if retry { logger.Debugw("error reading message", "error", err) return nil, err