From ef438d915e7bbbd33759c4cd7002a6bb1ceb3bdd Mon Sep 17 00:00:00 2001 From: Songlin Yang Date: Thu, 30 Nov 2023 14:10:18 +0800 Subject: [PATCH] fix(324): close channel after iterator is closed (#393) Fixed: https://github.com/streamnative/oxia/issues/324 Signed-off-by: Soren Yang --- server/leader_controller.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/server/leader_controller.go b/server/leader_controller.go index 32008d80..7c268fd7 100644 --- a/server/leader_controller.go +++ b/server/leader_controller.go @@ -630,6 +630,11 @@ func (lc *leaderController) list(ctx context.Context, request *proto.ListRequest defer func() { _ = it.Close() + // NOTE: + // we must close the channel after iterator is closed, to avoid the + // iterator keep open when caller is trying to process the next step (for example db.Close) + // because this is execute in another goroutine. + close(ch) }() for ; it.Valid(); it.Next() { @@ -638,7 +643,6 @@ func (lc *leaderController) list(ctx context.Context, request *proto.ListRequest break } } - close(ch) }) }