Skip to content

Commit

Permalink
Fix race condition error in http.get_rest_hosts when `fallback_real…
Browse files Browse the repository at this point in the history
…time_host` is set
  • Loading branch information
VeskeR committed Jan 9, 2025
1 parent f98e3d1 commit 36a599e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ably/http/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def get_rest_hosts(self):
if host is None:
return hosts

if time.time() > self.__host_expires:
# unstore saved fallback host after fallbackRetryTimeout (RSC15f)
if self.__host_expires is not None and time.time() > self.__host_expires:
self.__host = None
self.__host_expires = None
return hosts
Expand Down
13 changes: 13 additions & 0 deletions test/unit/http_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from ably import AblyRest


def test_http_get_rest_hosts_works_when_fallback_realtime_host_is_set():
ably = AblyRest(token="foo")
ably.options.fallback_realtime_host = ably.options.get_rest_hosts()[0]
assert ably.http.get_rest_hosts()


def test_http_get_rest_hosts_works_when_fallback_realtime_host_is_not_set():
ably = AblyRest(token="foo")
ably.options.fallback_realtime_host = None
assert ably.http.get_rest_hosts()

0 comments on commit 36a599e

Please sign in to comment.