From bb774b211b82025f4b246161b7d310e5e38d79bd Mon Sep 17 00:00:00 2001 From: yk Date: Wed, 29 May 2024 09:37:21 +0800 Subject: [PATCH] Fix network issue and use cache when network is down (#109) Relate to #108 I think it's not only an issue with http_proxy. I can reproduce this error without http_proxy settings by plug/unplug my network cable (forcing a connection issue during pacoloco's network activity), same problem will show up. After a little tinkering I think the problem is d is not ended by default. And I added f.cachedFileExists so that cache can be served. (Otherwise pacoloco would just return err without sending anything. https://github.com/anatol/pacoloco/blob/master/pacoloco.go#L270) This has a little bit downside, it would not register a cacheServingFailedCounter if cache is sent. But I guess that would not be a fail after all? --- downloader.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/downloader.go b/downloader.go index a5ee38a..9bd80ef 100644 --- a/downloader.go +++ b/downloader.go @@ -253,6 +253,12 @@ func getDownloadReader(f *RequestedFile) (time.Time, io.ReadSeekCloser, error) { } // we are done downloading without correctly received metadata, it is an error + // end 'd' properly + d.decrementUsage() + // if cache exists, use that + if f.cachedFileExists() { + return time.Time{}, nil, nil + } return time.Time{}, nil, d.eventError }