Skip to content

Conversation

Tymek
Copy link
Member

@Tymek Tymek commented Sep 12, 2025

Refactor streaming connector to add disconnect logging and simplify _run.

I changed iteration to client.all from client.events to log disconnection warnings. After that _run had deep nesting. I pulled setup, event handling, error handling, and cleanup into smaller, flatter methods.

Example log when disconnected from Edge now looks like this:

INFO:UnleashClient:Connecting to stream at http://localhost:3063/api/client/streaming
DEBUG:urllib3.connectionpool:Resetting dropped connection: localhost
WARNING:UnleashClient:SSE stream error: <urllib3.connection.HTTPConnection object at 0x7fb2863b02d0>: Failed to establish a new connection: [Errno 111] Connection refused - will retry
INFO:UnleashClient:Will reconnect after delay of 3.090826s

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes.

  • Unit tests
  • Spec Tests
  • Integration tests / Manual Tests

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@Tymek Tymek requested review from kwasniew and sighphyre September 12, 2025 09:19
@coveralls
Copy link

Pull Request Test Coverage Report for Build 17670269762

Details

  • 33 of 41 (80.49%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.1%) to 94.083%

Changes Missing Coverage Covered Lines Changed/Added Lines %
UnleashClient/connectors/streaming_connector.py 33 41 80.49%
Totals Coverage Status
Change from base Build 17488384346: 0.1%
Covered Lines: 636
Relevant Lines: 676

💛 - Coveralls

@Tymek Tymek marked this pull request as ready for review September 12, 2025 09:52
LOGGER.error("Error applying streaming state", exc_info=True)
self.load_features()
else:
LOGGER.warning("Ignoring SSE event type: %s", item.event)
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure if for the unknown events we want warnings or maybe debug instead

Copy link
Contributor

Choose a reason for hiding this comment

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

we may add new event types over time and it's not sth to warn about and pollute logs at this level

@gastonfournier gastonfournier moved this from New to In Progress in Issues and PRs Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

3 participants