Recently, I observed that when using bitswap for fetching data, there is a large amount of memory consumption and no release after downloading.
I use pprof and find most heap is occupied here.
|
bpm.presence[c] = make(map[peer.ID]bool) |
I try to print stat after bpm.presence[c] = make(map[peer.ID]bool) and I found bpm.presence would delete on BlockPresenceManager.RemoveKeys, so I added some logs.
I found that there is a race condition problem here.
BlockPresenceManager.RemoveKeys has been called and remove the CidA
BlockPresenceManager.ReceiveFrom has been called and created bpm.presence[CidA]
bpm.presence[CidA] is no longer used or removed, and the map is getting bigger and bigger.
Recently, I observed that when using bitswap for fetching data, there is a large amount of memory consumption and no release after downloading.
I use pprof and find most heap is occupied here.
boxo/bitswap/client/internal/blockpresencemanager/blockpresencemanager.go
Line 40 in 89bceff
I try to print stat after
bpm.presence[c] = make(map[peer.ID]bool)and I foundbpm.presencewould delete onBlockPresenceManager.RemoveKeys, so I added some logs.I found that there is a race condition problem here.
BlockPresenceManager.RemoveKeyshas been called and remove the CidABlockPresenceManager.ReceiveFromhas been called and createdbpm.presence[CidA]bpm.presence[CidA]is no longer used or removed, and the map is getting bigger and bigger.