Skip to content

Conversation

@luxscious
Copy link
Contributor

@luxscious luxscious commented Jan 27, 2026

feat: add exponential backoff strategy for SSE reconnection
fix: wrap client.start() in try catch

to prevent instances where we try to reconnect forever and spam the server.
fix: bug where client crashes when http error code received.
chore: lint errors
@luxscious luxscious changed the title fix: attempt to reconnect to sse server when response ends prematurely. fix: sse error handling Jan 27, 2026
@luxscious luxscious marked this pull request as ready for review January 27, 2026 20:20
@luxscious luxscious requested a review from a team as a code owner January 27, 2026 20:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves SSE robustness by propagating read-loop failures to the error handler and introducing an exponential backoff strategy for SSE reconnection.

Changes:

  • Wraps SSEClient.start() and the read loop in try/except/finally, forwarding failures to the configured error handler.
  • Adds exponential backoff + delayed reconnection thread orchestration in EnvironmentConfigManager.sse_error.
  • Fixes use_new_config boolean precedence for correct SSE URL change detection.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
devcycle_python_sdk/managers/sse_manager.py Wraps SSE read loop in error handling and forwards exceptions to the error callback; fixes URL-change condition precedence.
devcycle_python_sdk/managers/config_manager.py Adds exponential backoff reconnection logic and SSE connection recreation/teardown handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI commented Jan 27, 2026

@JamieSinn I've opened a new pull request, #108, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Update test_config_manager.py
@luxscious luxscious force-pushed the bug-sse-connection-dropping-after-premature-response-end branch from 08cd028 to 4baf61e Compare January 27, 2026 22:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 158 to +249
def close(self):
self._polling_enabled = False
if self._sse_manager is not None and self._sse_manager.client is not None:
self._sse_manager.client.close()
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

close() currently only closes the SSE client, but it does not stop/join the SSE read thread (SSEManager.read_thread) and does not clear reconnection state. This can leave background threads running after close(). Consider joining the read thread with a timeout and preventing any further reconnect attempts as part of shutdown.

Copilot uses AI. Check for mistakes.
@luxscious luxscious enabled auto-merge (squash) January 27, 2026 22:17
Copilot AI review requested due to automatic review settings January 27, 2026 22:18
@luxscious luxscious merged commit 708d696 into main Jan 27, 2026
17 checks passed
@luxscious luxscious deleted the bug-sse-connection-dropping-after-premature-response-end branch January 27, 2026 22:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 48 to +52
except Exception as e:
logger.debug(f"DevCycle: failed to read SSE message: {e}")
logger.debug(f"DevCycle SSE: Error in read loop: {e}")
fault_event = ld_eventsource.actions.Fault(error=e)
handle_error(fault_event)
finally:
Copy link

Copilot AI Jan 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

read_events() now converts any exception into a Fault and calls handle_error(). If the exception is caused by an intentional shutdown (client.close()), this will trigger the reconnection logic and can fight against EnvironmentConfigManager.close(). Consider detecting/ignoring expected shutdown exceptions (or relying on a shutdown flag in the error handler to suppress reconnects during close).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants