Skip to content

Commit b1b06bd

Browse files
authored
Merge pull request #19 from ipfs/bugs/fix-leftover-go-routines
Wait for all go routines to finish before function returns
2 parents 7e8e37d + d845d6a commit b1b06bd

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

merkledag.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -376,14 +376,16 @@ func EnumerateChildrenAsyncDepth(ctx context.Context, getLinks GetLinks, c cid.C
376376
done := make(chan struct{})
377377

378378
var setlk sync.Mutex
379+
var wg sync.WaitGroup
379380

380381
errChan := make(chan error)
381382
fetchersCtx, cancel := context.WithCancel(ctx)
382-
383+
defer wg.Wait()
383384
defer cancel()
384-
385385
for i := 0; i < FetchGraphConcurrency; i++ {
386+
wg.Add(1)
386387
go func() {
388+
defer wg.Done()
387389
for cdepth := range feed {
388390
ci := cdepth.cid
389391
depth := cdepth.depth

0 commit comments

Comments
 (0)