Timeout problems with http-calls to geojs-API
toddietaste opened this issue · comments
Hi, big thanks for providing this plugin!
I am frequently seeing errors in my traefik log because GeoBlock is running into timeouts when calling the geojs-API:
time="2022-03-30T22:42:40Z" level=error msg="2022/03/30 22:42:40 Get \"https://get.geojs.io/v1/ip/country/51.254.49.108\": context deadline exceeded (Client.Timeout exceeded while awaiting headers)" module=github.com/PascalMinder/GeoBlock plugin=plugin-GeoBlock
The http-timeout for API-calls currently seems to be hardcoded to 750ms in the CallGeoJS function, which may not be sufficient for all environments. It definitely isn't for mine :(
> time curl https://get.geojs.io/v1/ip/country/51.254.49.108
FR
real 0m3.227s
user 0m0.062s
sys 0m0.019s
Would be great to have the http-timeout configurable, i.e. by adding a new (optional) config like 'apiTimeoutMs', which would override the current default if set.
Thanks for considering!
Hey, thanks for opening the issue. I'll look into it.
@toddietaste I created a branch for the issue: #15
I tested the api-timeout branch as a local plugin. Works for me!
Tested:
- setting apiTimeoutMs to 5000 -> getting result from API, request allowed/denied depending on resulting country -> as expected
- setting apiTimeoutMs to 750 -> error because of API call timing out (for me), request denied -> as expected
- not setting apiTimeoutMs -> defaults to 750ms according to log, with API call timing out, request denied -> as expected
Thanks!
Thank you very much for testing. I released v0.2.2