aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/storage/netstore.go
diff options
context:
space:
mode:
authorElad <theman@elad.im>2019-02-14 14:51:57 +0800
committerRafael Matias <rafael@skyle.net>2019-02-19 20:11:52 +0800
commit79cac793c013832457a89911cc477f345e46ced9 (patch)
treef37553372cec94f0c5627bb0d5b3de1f1fbd1699 /swarm/storage/netstore.go
parent5de6b6b529ea3fc0ad5cd9791d5f3ac44f497d65 (diff)
downloaddexon-79cac793c013832457a89911cc477f345e46ced9.tar
dexon-79cac793c013832457a89911cc477f345e46ced9.tar.gz
dexon-79cac793c013832457a89911cc477f345e46ced9.tar.bz2
dexon-79cac793c013832457a89911cc477f345e46ced9.tar.lz
dexon-79cac793c013832457a89911cc477f345e46ced9.tar.xz
dexon-79cac793c013832457a89911cc477f345e46ced9.tar.zst
dexon-79cac793c013832457a89911cc477f345e46ced9.zip
swarm/storage/netstore: add fetcher cancellation on shutdown (#19049)
swarm/network/stream: remove netstore internal wg swarm/network/stream: run individual tests with t.Run (cherry picked from commit 3ee09ba03511ad9a49e37c58f0c35b9c9771dd6f)
Diffstat (limited to 'swarm/storage/netstore.go')
-rw-r--r--swarm/storage/netstore.go20
1 files changed, 19 insertions, 1 deletions
diff --git a/swarm/storage/netstore.go b/swarm/storage/netstore.go
index a2595d9fa..202af2bf5 100644
--- a/swarm/storage/netstore.go
+++ b/swarm/storage/netstore.go
@@ -128,7 +128,25 @@ func (n *NetStore) FetchFunc(ctx context.Context, ref Address) func(context.Cont
func (n *NetStore) Close() {
close(n.closeC)
n.store.Close()
- // TODO: loop through fetchers to cancel them
+
+ wg := sync.WaitGroup{}
+ for _, key := range n.fetchers.Keys() {
+ if f, ok := n.fetchers.Get(key); ok {
+ if fetch, ok := f.(*fetcher); ok {
+ wg.Add(1)
+ go func(fetch *fetcher) {
+ defer wg.Done()
+ fetch.cancel()
+
+ select {
+ case <-fetch.deliveredC:
+ case <-fetch.cancelledC:
+ }
+ }(fetch)
+ }
+ }
+ }
+ wg.Wait()
}
// get attempts at retrieving the chunk from LocalStore