Skip to content

Commit 35cca9a

Browse files
authored
Merge pull request #705 from libp2p/feat/unlock-refresh
Routing table refresh should NOT block
2 parents a8d4bf3 + e742220 commit 35cca9a

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

rtrefresh/rt_refresh_manager.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,18 @@ func (r *RtRefreshManager) Close() error {
102102
//
103103
// The returned channel will block until the refresh finishes, then yield the
104104
// error and close. The channel is buffered and safe to ignore.
105-
// FIXME: this can block. Ideally, we'd return a channel without blocking.
106-
// https://github.com/libp2p/go-libp2p-kad-dht/issues/609
107105
func (r *RtRefreshManager) Refresh(force bool) <-chan error {
108106
resp := make(chan error, 1)
109-
select {
110-
case r.triggerRefresh <- &triggerRefreshReq{respCh: resp, forceCplRefresh: force}:
111-
case <-r.ctx.Done():
112-
resp <- r.ctx.Err()
113-
}
107+
r.refcount.Add(1)
108+
go func() {
109+
defer r.refcount.Done()
110+
select {
111+
case r.triggerRefresh <- &triggerRefreshReq{respCh: resp, forceCplRefresh: force}:
112+
case <-r.ctx.Done():
113+
resp <- r.ctx.Err()
114+
}
115+
}()
116+
114117
return resp
115118
}
116119

0 commit comments

Comments
 (0)