From bcace47dddb9aafc9e312d72c5a4cf1d80ee93e0 Mon Sep 17 00:00:00 2001 From: dirkmc Date: Thu, 2 Sep 2021 09:46:59 +0200 Subject: [PATCH] fix: ensure graphsync transport only closes complete channel once (#250) --- transport/graphsync/graphsync.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/transport/graphsync/graphsync.go b/transport/graphsync/graphsync.go index cc833d18..7adc51c7 100644 --- a/transport/graphsync/graphsync.go +++ b/transport/graphsync/graphsync.go @@ -894,9 +894,13 @@ func (c *dtChannel) open(ctx context.Context, chid datatransfer.ChannelID, dataS // Set up a completed channel that will be closed when the request // completes (or is cancelled) completed := make(chan struct{}) + var onCompleteOnce sync.Once onComplete := func() { - log.Infow("closing the completion ch for data-transfer channel", "chid", chid) - close(completed) + // Ensure the channel is only closed once + onCompleteOnce.Do(func() { + log.Infow("closing the completion ch for data-transfer channel", "chid", chid) + close(completed) + }) } c.completed = completed