diff options
author | Balint Gabor <balint.g@gmail.com> | 2018-09-19 22:59:10 +0800 |
---|---|---|
committer | Anton Evangelatov <anton.evangelatov@gmail.com> | 2018-09-19 22:59:10 +0800 |
commit | f5c7d1c8eb202b850541a3fcfc2e9bd4ee6f70a9 (patch) | |
tree | 48feff3cd06cda592922204eb416c5d24b89dc1c | |
parent | 736b45a87606e6cdfd5aecf38d259517b10e7f7e (diff) | |
download | go-tangerine-f5c7d1c8eb202b850541a3fcfc2e9bd4ee6f70a9.tar go-tangerine-f5c7d1c8eb202b850541a3fcfc2e9bd4ee6f70a9.tar.gz go-tangerine-f5c7d1c8eb202b850541a3fcfc2e9bd4ee6f70a9.tar.bz2 go-tangerine-f5c7d1c8eb202b850541a3fcfc2e9bd4ee6f70a9.tar.lz go-tangerine-f5c7d1c8eb202b850541a3fcfc2e9bd4ee6f70a9.tar.xz go-tangerine-f5c7d1c8eb202b850541a3fcfc2e9bd4ee6f70a9.tar.zst go-tangerine-f5c7d1c8eb202b850541a3fcfc2e9bd4ee6f70a9.zip |
swarm/storage: Implement global timeout for fetcher (#17702)
-rw-r--r-- | swarm/storage/netstore.go | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/swarm/storage/netstore.go b/swarm/storage/netstore.go index de2d82d2b..80ac6f198 100644 --- a/swarm/storage/netstore.go +++ b/swarm/storage/netstore.go @@ -52,6 +52,8 @@ type NetStore struct { closeC chan struct{} } +var fetcherTimeout = 2 * time.Minute // timeout to cancel the fetcher even if requests are coming in + // NewNetStore creates a new NetStore object using the given local store. newFetchFunc is a // constructor function that can create a fetch function for a specific chunk address. func NewNetStore(store SyncChunkStore, nnf NewNetFetcherFunc) (*NetStore, error) { @@ -168,7 +170,7 @@ func (n *NetStore) getOrCreateFetcher(ref Address) *fetcher { // no fetcher for the given address, we have to create a new one key := hex.EncodeToString(ref) // create the context during which fetching is kept alive - ctx, cancel := context.WithCancel(context.Background()) + ctx, cancel := context.WithTimeout(context.Background(), fetcherTimeout) // destroy is called when all requests finish destroy := func() { // remove fetcher from fetchers |