Skip to content

Commit bcace47

Browse files
authored
fix: ensure graphsync transport only closes complete channel once (#250)
1 parent b0599c7 commit bcace47

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

transport/graphsync/graphsync.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -894,9 +894,13 @@ func (c *dtChannel) open(ctx context.Context, chid datatransfer.ChannelID, dataS
894894
// Set up a completed channel that will be closed when the request
895895
// completes (or is cancelled)
896896
completed := make(chan struct{})
897+
var onCompleteOnce sync.Once
897898
onComplete := func() {
898-
log.Infow("closing the completion ch for data-transfer channel", "chid", chid)
899-
close(completed)
899+
// Ensure the channel is only closed once
900+
onCompleteOnce.Do(func() {
901+
log.Infow("closing the completion ch for data-transfer channel", "chid", chid)
902+
close(completed)
903+
})
900904
}
901905
c.completed = completed
902906

0 commit comments

Comments
 (0)