Skip to content

Commit 22218a8

Browse files
committed
possible deadlock fix
1 parent 1d012bd commit 22218a8

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

cmd/migration-checker/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,18 @@ func loadZkTrie(zkTrie *trie.ZkTrie, top, paranoid bool) chan map[string][]byte
255255
fmt.Println("ZK Accounts Loaded:", len(zkLeafMap))
256256
}
257257
}, func(f func()) {
258-
<-trieLoaders
258+
select {
259+
case <-trieLoaders:
260+
case <-time.After(time.Minute * 5):
261+
f()
262+
return
263+
}
264+
259265
go func() {
266+
defer func() {
267+
trieLoaders <- struct{}{}
268+
}()
260269
f()
261-
trieLoaders <- struct{}{}
262270
}()
263271
}, parallelismCutoffDepth, paranoid)
264272
zkDone <- zkLeafMap

trie/zk_trie.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,12 @@ func (t *ZkTrie) countLeaves(depth int, root *zkt.Hash, cb func(key, value []byt
272272
return 1
273273
} else {
274274
if depth < parallelismCutoffDepth {
275-
count := make(chan uint64)
275+
count := make(chan uint64, 1)
276276
leftT := t.Copy()
277-
rightT := t.Copy()
278-
go func() {
279-
spawnWorker(func() {
280-
count <- leftT.countLeaves(depth+1, rootNode.ChildL, cb, spawnWorker, parallelismCutoffDepth, verifyNodeHashes)
281-
})
282-
}()
283-
return rightT.countLeaves(depth+1, rootNode.ChildR, cb, spawnWorker, parallelismCutoffDepth, verifyNodeHashes) + <-count
277+
spawnWorker(func() {
278+
count <- leftT.countLeaves(depth+1, rootNode.ChildL, cb, spawnWorker, parallelismCutoffDepth, verifyNodeHashes)
279+
})
280+
return t.countLeaves(depth+1, rootNode.ChildR, cb, spawnWorker, parallelismCutoffDepth, verifyNodeHashes) + <-count
284281
} else {
285282
return t.countLeaves(depth+1, rootNode.ChildL, cb, spawnWorker, parallelismCutoffDepth, verifyNodeHashes) +
286283
t.countLeaves(depth+1, rootNode.ChildR, cb, spawnWorker, parallelismCutoffDepth, verifyNodeHashes)

0 commit comments

Comments
 (0)