Skip to content

Commit 378f27c

Browse files
committed
fix: Log and no-op instead of raising when start() is called on a closed client
Every other LaunchDarkly server SDK (sync Python, Go, .NET, Node, Ruby) degrades lifecycle misuse to a logged no-op rather than throwing. Match that: start() on a closed AsyncLDClient logs a warning and returns.
1 parent f3a578f commit 378f27c

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

‎ldclient/async_client.py‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,15 @@ def __init__(self, config: AsyncConfig):
108108
async def start(self, start_wait: float = 5.0) -> None:
109109
"""Start the client: create the HTTP session, data system, and event processor.
110110
111-
Safe to call multiple times — subsequent calls are no-ops.
111+
Safe to call multiple times — subsequent calls are no-ops. Calling start()
112+
after close() logs a warning and does nothing; the client stays closed.
112113
113114
:param start_wait: seconds to wait for the data source to initialize
114115
"""
115116
async with self._lifecycle_lock:
116117
if self._closed:
117-
raise RuntimeError("Cannot start a closed AsyncLDClient")
118+
log.warning("start() called on a closed AsyncLDClient; ignoring")
119+
return
118120
if self._started:
119121
return
120122

‎ldclient/testing/test_async_client.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,14 @@ async def after_evaluation(self, series_context, data, detail):
353353

354354

355355
@pytest.mark.asyncio
356-
async def test_start_after_close_raises():
357-
"""Calling start() after close() raises RuntimeError."""
356+
async def test_start_after_close_is_noop():
357+
"""Calling start() after close() logs a warning and does nothing; the client stays closed."""
358358
client = AsyncLDClient(_offline_config())
359359
await client.start()
360360
await client.close()
361-
with pytest.raises(RuntimeError):
362-
await client.start()
361+
# Does not raise; the client remains closed.
362+
await client.start()
363+
assert client._closed is True
363364

364365

365366
@pytest.mark.asyncio

0 commit comments

Comments
 (0)