Skip to content

Commit 20cbabf

Browse files
committed
Fix race condition in http.get_rest_hosts when fallback_realtime_host is set
1 parent f98e3d1 commit 20cbabf

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

ably/http/http.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ def get_rest_hosts(self):
146146
if host is None:
147147
return hosts
148148

149-
if time.time() > self.__host_expires:
149+
# unstore saved fallback host after fallbackRetryTimeout (RSC15f)
150+
if self.__host_expires is not None and time.time() > self.__host_expires:
150151
self.__host = None
151152
self.__host_expires = None
152153
return hosts

test/unit/http_test.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from ably import AblyRest
2+
3+
4+
def test_http_get_rest_hosts_works_when_fallback_realtime_host_is_set():
5+
ably = AblyRest(token="foo")
6+
ably.options.fallback_realtime_host = ably.options.get_rest_hosts()[0]
7+
assert ably.http.get_rest_hosts()
8+
9+
10+
def test_http_get_rest_hosts_works_when_fallback_realtime_host_is_not_set():
11+
ably = AblyRest(token="foo")
12+
ably.options.fallback_realtime_host = None
13+
assert ably.http.get_rest_hosts()

0 commit comments

Comments
 (0)