Skip to content

Commit ff3993f

Browse files
authored
FFM-6932 - SDK seems to disconnect from the relay proxy (#57)
* FFM-6932 - SDK seems to disconnect from the relay proxy What Add timeout parameter of 60 seconds to HTTP request to force socket to time out if no data arrives. The timeout will trigger an exception so that the poller is restarted. Also before putting the poller to sleep when stream is enabled, make sure we retrieve the flags. Why Customers are reporting SSE updates stopping and flags getting out of date Testing Manual - ensured that after connection was lost to SSE stream that the poller is restarted
1 parent 169b2f2 commit ff3993f

File tree

7 files changed

+12
-6
lines changed

7 files changed

+12
-6
lines changed

examples/getting_started/getting_started.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def main():
2424
# Loop forever reporting the state of the flag
2525
while True:
2626
result = client.bool_variation(flagName, target, False)
27-
log.info("Flag variation %s", result)
27+
log.info("%s flag variation %s", flagName, result)
2828
time.sleep(10)
2929

3030
close()

featureflags/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__author__ = """Enver Bisevac"""
44
__email__ = "[email protected]"
5-
__version__ = '1.1.8'
5+
__version__ = '1.1.9'

featureflags/polling.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ def run(self):
6565
self.__stream_ready.is_set():
6666
log.debug('Poller will be paused because' +
6767
' streaming mode is active')
68+
# on stream disconnect, make sure flags are in sync
69+
self.retrieve_flags_and_segments()
6870
# Block until ready.set() is called
6971
self.__ready.wait()
7072
log.debug('Poller resuming ')

featureflags/sse_client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ def __init__(
4848
# The 'Accept' header is not required, but explicit > implicit
4949
self.requests_kwargs["headers"]["Accept"] = "text/event-stream"
5050

51+
# If we haven't gotten any heartbeats from the server in 60 seconds,
52+
# then we assume the socket has died
53+
self.requests_kwargs["timeout"] = 60
54+
5155
# Keep data here as it streams in
5256
self.buf: str = ""
5357

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.1.8
2+
current_version = 1.1.9
33
commit = True
44
tag = True
55

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@
5656
test_suite="tests",
5757
tests_require=test_requirements,
5858
url="https://github.com/harness/ff-python-server-sdk",
59-
version='1.1.8',
59+
version='1.1.9',
6060
zip_safe=False,
6161
)

tests/unit/test_sse_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def multiple_responses(monkeypatch):
166166
fake_get.assert_called_once_with(
167167
"http://blah.com",
168168
headers={"Accept": "text/event-stream", "Cache-Control": "no-cache"},
169-
stream=True,
169+
stream=True, timeout=60
170170
)
171171

172172

@@ -244,7 +244,7 @@ def unicode_multibyte_responses(monkeypatch):
244244
fake_get.assert_called_once_with(
245245
"http://blah.com",
246246
headers={"Accept": "text/event-stream", "Cache-Control": "no-cache"},
247-
stream=True,
247+
stream=True, timeout=60
248248
)
249249

250250

0 commit comments

Comments
 (0)