Skip to content

bugfix: fix threading races and concurrency in moonrakerComm/RepeatedTimer#211

Open
gmmcosta15 wants to merge 2 commits intodevfrom
bugfix/threading-concurrency
Open

bugfix: fix threading races and concurrency in moonrakerComm/RepeatedTimer#211
gmmcosta15 wants to merge 2 commits intodevfrom
bugfix/threading-concurrency

Conversation

@gmmcosta15
Copy link
Copy Markdown
Collaborator

  • Feature
  • Bug fix
  • Code refactor
  • Documentation

Description

  • Move connected, connecting, _reconnect_count, callback_table from class-level to __init__ to prevent shared state across instances.
  • Add _state_lock (RLock) and _request_lock guarding all reads/writes to those vars.
  • Fix mutable default argument params={}params=None in send_request.
  • Fix unbound super() in OneShotTokenError.
  • Guard _retry_timer with None check before stopTimer/startTimer; stop existing timer in try_connection before creating a new one (prevents orphaned threads).
  • Replace sendEventpostEvent for safe cross-thread event delivery.
  • Wrap json.loads in try/except; use .get() on all external response dicts.
  • Add klippy startup/disconnected retry cap (30 attempts) to prevent infinite reconnect loop.
  • Add join(timeout=self.timeout+1) on _wst to avoid indefinite block on shutdown.
  • Fix RepeatedTimer: inverted stopEvent semantics (set=stop, clear=running).

Motivation

The WebSocket layer had multiple threading races and incorrect cross-thread event dispatch causing UI freezes and crashes on Pi hardware. RepeatedTimer had inverted stop-event logic causing timers to never stop correctly. These are the root-cause fixes for the most severe class of bugs in #200.

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.

1 participant