Skip to content

Commit 3e75354

Browse files
committed
FIX: Fix Live client InvalidStateError
1 parent 5b59ef8 commit 3e75354

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## 0.39.3 - TBD
4+
5+
#### Bug fixes
6+
- Fixed an issue receiving multiple DBN v1 `ErrorMsg` in the `Live` client would cause an `InvalidState` error
7+
38
## 0.39.2 - 2024-08-13
49

510
#### Enhancements

databento/live/protocol.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,16 @@ def connection_lost(self, exc: Exception | None) -> None:
197197
if not self.disconnected.done():
198198
if exc is None:
199199
logger.info("connection closed")
200-
self.disconnected.set_result(None)
200+
if self._error_msgs:
201+
error_msg = ", ".join(self._error_msgs)
202+
if len(self._error_msgs) > 1:
203+
error_msg = f"The following errors occurred: {error_msg}"
204+
self._error_msgs.clear()
205+
self.disconnected.set_exception(
206+
BentoError(error_msg),
207+
)
208+
else:
209+
self.disconnected.set_result(None)
201210
else:
202211
logger.error("connection lost: %s", exc)
203212
self.disconnected.set_exception(exc)
@@ -361,17 +370,7 @@ def _process_dbn(self, data: bytes) -> None:
361370
record.err,
362371
)
363372
self._error_msgs.append(record.err)
364-
if record.is_last:
365-
if len(self._error_msgs) > 1:
366-
errors = ", ".join(self._error_msgs)
367-
error_msg = f"The following errors occurred: {errors}"
368-
else:
369-
error_msg = self._error_msgs[-1]
370-
self._error_msgs.clear()
371-
self.disconnected.set_exception(
372-
BentoError(error_msg),
373-
)
374-
if isinstance(record, databento_dbn.SystemMsg):
373+
elif isinstance(record, databento_dbn.SystemMsg):
375374
if record.is_heartbeat:
376375
logger.debug("gateway heartbeat")
377376
else:

0 commit comments

Comments
 (0)