-
Notifications
You must be signed in to change notification settings - Fork 6
fix: handle SSE connection state when Start events are not received #105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,7 +82,10 @@ def _get_config(self, last_modified: Optional[float] = None): | |
| json_config = json.dumps(self._config) | ||
| self._local_bucketing.store_config(json_config) | ||
| if not self._options.disable_realtime_updates: | ||
| if self._sse_manager is None: | ||
| if ( | ||
| self._sse_manager is None | ||
| or not self._sse_manager.client.is_connected() | ||
| ): | ||
| self._sse_manager = SSEManager( | ||
| self.sse_state, | ||
| self.sse_error, | ||
|
|
@@ -128,9 +131,9 @@ def run(self): | |
| time.sleep(self._options.config_polling_interval_ms / 1000.0) | ||
|
|
||
| def sse_message(self, message: ld_eventsource.actions.Event): | ||
| if self._sse_connected is False: | ||
| self._sse_connected = True | ||
| logger.info("DevCycle: Connected to SSE stream") | ||
| # Received a message from the SSE stream but our sse_connected is False, so we need to set it to True | ||
| if not self._sse_connected: | ||
| self.sse_state(None) | ||
| logger.info(f"DevCycle: Received message: {message.data}") | ||
| sse_message = json.loads(message.data) | ||
| dvc_data = json.loads(sse_message.get("data")) | ||
|
|
@@ -143,11 +146,13 @@ def sse_message(self, message: ld_eventsource.actions.Event): | |
| self._get_config(dvc_data["lastModified"] / 1000.0) | ||
|
|
||
| def sse_error(self, error: ld_eventsource.actions.Fault): | ||
| self._sse_connected = False | ||
| logger.debug(f"DevCycle: Received SSE error: {error}") | ||
|
|
||
| def sse_state(self, state: ld_eventsource.actions.Start): | ||
| self._sse_connected = True | ||
| logger.info("DevCycle: Connected to SSE stream") | ||
| def sse_state(self, state: Optional[ld_eventsource.actions.Start]): | ||
|
||
| if not self._sse_connected: | ||
| self._sse_connected = True | ||
| logger.info("DevCycle: Connected to SSE stream") | ||
|
Comment on lines
+149
to
+155
|
||
|
|
||
| def close(self): | ||
| self._polling_enabled = False | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potential AttributeError when accessing
self._sse_manager.client.is_connected(). The SSEManager's client attribute is initialized to None in the constructor and only gets assigned when the update() method is called. This check could raise an AttributeError if the SSEManager exists but update() hasn't been called yet. Consider adding a None check for the client before calling is_connected().