Skip to content

Comments

Fix EchoReader blocking indefinitely after transient exceptions#23

Merged
JohnCHarrington merged 2 commits intorefactor-python-codefrom
copilot/sub-pr-17-another-one
Feb 19, 2026
Merged

Fix EchoReader blocking indefinitely after transient exceptions#23
JohnCHarrington merged 2 commits intorefactor-python-codefrom
copilot/sub-pr-17-another-one

Conversation

Copy link

Copilot AI commented Feb 19, 2026

After any exception in the reader loop (e.g., serial/UDP drop), run_forever fell through to await self._restart_event.wait() — blocking until settings were manually updated, with no automatic recovery.

Changes

  • Retry with exponential backoff on exceptions: on error, sleeps 1s → 2s → 4s → … → 30s cap, then retries automatically
  • _restart_event.wait() only on clean exit: moved inside the try block so exceptions take the backoff path instead
  • Backoff resets on clean exit: after a deliberate settings-driven restart, the delay counter resets to 1s
# Before: exceptions always fell through to this, blocking forever
await self._restart_event.wait()

# After: clean exit waits for restart; exceptions retry with backoff
try:
    async with reader:
        async for pkt in reader:
            ...
    retry_delay = 1  # reset on clean exit
    await self._restart_event.wait()
except Exception as e:
    log.error(f"❌ Error in EchoReader: {e}", exc_info=e)
    await asyncio.sleep(retry_delay)
    retry_delay = min(retry_delay * 2, 30)

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: JohnCHarrington <1857365+JohnCHarrington@users.noreply.github.com>
Copilot AI changed the title [WIP] WIP Address feedback from PR #17 on code refactoring Fix EchoReader blocking indefinitely after transient exceptions Feb 19, 2026
@JohnCHarrington JohnCHarrington marked this pull request as ready for review February 19, 2026 11:31
@JohnCHarrington JohnCHarrington merged commit e930c7e into refactor-python-code Feb 19, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants