Skip to content

Commit ea4dc19

Browse files
committed
fix: Reject a poll interval longer than the runtime can wait
1 parent 60bef61 commit ea4dc19

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎ldclient/integrations/overrides.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"""
2828

2929
import math
30+
import threading
3031
from typing import List, Optional, Union
3132

3233
from ldclient.config import DataSourceBuilderConfig, OverrideSourceBuilder
@@ -128,12 +129,15 @@ def poll_interval(self, seconds: float) -> 'FileOverrideSourceBuilder':
128129
129130
:param seconds: the interval in seconds
130131
:raises TypeError: when the interval is not a number
131-
:raises ValueError: when the interval is not a finite number
132+
:raises ValueError: when the interval is not a finite number, or is longer than the
133+
runtime can wait
132134
"""
133135
if isinstance(seconds, bool) or not isinstance(seconds, (int, float)):
134136
raise TypeError("the poll interval must be a number of seconds")
135137
if not math.isfinite(seconds):
136138
raise ValueError("the poll interval must be a finite number of seconds")
139+
if seconds > threading.TIMEOUT_MAX:
140+
raise ValueError("the poll interval must not exceed %s seconds" % threading.TIMEOUT_MAX)
137141
self.__poll_interval = seconds
138142
return self
139143

‎ldclient/testing/integrations/test_file_override_source.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,12 @@ def test_builder_rejects_a_poll_interval_that_is_not_a_number(seconds):
171171
FileOverrideSourceBuilder(['a']).poll_interval(seconds)
172172

173173

174+
def test_builder_rejects_a_poll_interval_longer_than_the_runtime_can_wait():
175+
with pytest.raises(ValueError) as excinfo:
176+
FileOverrideSourceBuilder(['a']).poll_interval(1e20)
177+
assert 'must not exceed' in str(excinfo.value)
178+
179+
174180
@pytest.mark.parametrize('seconds', [float('nan'), float('inf'), float('-inf')], ids=['nan', 'inf', '-inf'])
175181
def test_builder_rejects_a_poll_interval_that_is_not_finite(seconds):
176182
with pytest.raises(ValueError):

0 commit comments

Comments
 (0)