anatol / pacoloco

Caching proxy server for Arch Linux pacman
MIT License
216 stars 30 forks source link

Fix network issue and use cache when network is down #109

Closed ykelvis closed 4 months ago

ykelvis commented 4 months ago

Relate to https://github.com/anatol/pacoloco/issues/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?

anatol commented 4 months ago

Thank you for tracking down this issue and providing the fix. The change looks good to me. But we also need a test for this error case. Something similar to tests here https://github.com/anatol/pacoloco/blob/master/integration_test.go

anatol commented 4 months ago

It looks like implementing such test might not be a trivial task as I thought initially.

Let's move forward with the fix. Having an integration test for faulty network would still be beneficial.