jellyfin / mopidy-jellyfin

Jellyfin Extension for Mopidy
https://jellyfin.org
Apache License 2.0
93 stars 16 forks source link

Improve retry logic #141

Open Malinskiy opened 1 year ago

Malinskiy commented 1 year ago

Current logic for http requests just retries immediately which leads to doing all the retries one after the other https://github.com/jellyfin/mopidy-jellyfin/blob/master/mopidy_jellyfin/http.py#L53

Context: I have an embedded box with mopidy + jellyfin starting during systemd boot. The problem is even though network.target is up the network is not really available at this point for mopidy-jellyfin, hence the HTTP connection might fail.

Jun 04 16:21:20 schiit mopidy[361]: ERROR    2023-06-04 16:21:20,039 [361:MainThread] mopidy_jellyfin.http
Jun 04 16:21:20 schiit mopidy[361]:   Failed to reach Jellyfin public API on try 0 with problem: HTTPSConnectionPool(host='jellyfin.home.XXX', port=443): Max retries exceeded with url: /system/info/public (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f88235da590>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))
....
Jun 04 16:21:20 schiit mopidy[361]: ERROR    2023-06-04 16:21:20,046 [361:MainThread] mopidy_jellyfin.http
Jun 04 16:21:20 schiit mopidy[361]:   Failed to reach Jellyfin public API on try 5 with problem: HTTPSConnectionPool(host='jellyfin.home.XXX', port=443): Max retries exceeded with url: /system/info/public (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x7f88235da590>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution'))

Suggestion: exponential backoff for temporary network failure