Commit b30b7b48 authored by Brian Tiger Chow's avatar Brian Tiger Chow

fix(dht/routing) buffer promise response to prevent resource leak

When performing this "promise" pattern, it is important to
provide a
channel with space for one value. Otherwise the sender may
block forever
in the case of a receiver that decides to abandon the
request. A subtle
detail, but one that is important for avoiding
leaked goroutines.

cc @whyrusleeping @jbenet

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>

License: MIT
Signed-off-by: default avatarBrian Tiger Chow <brian@perfmode.com>
parent add43e52
......@@ -102,9 +102,10 @@ func (pm *ProviderManager) AddProvider(k u.Key, val peer.Peer) {
}
func (pm *ProviderManager) GetProviders(ctx context.Context, k u.Key) []peer.Peer {
gp := new(getProv)
gp.k = k
gp.resp = make(chan []peer.Peer)
gp := &getProv{
k: k,
resp: make(chan []peer.Peer, 1), // buffered to prevent sender from blocking
}
select {
case pm.getprovs <- gp:
return <-gp.resp
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment