Skip to content

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

Merged
gmmcosta15 merged 18 commits into
devfrom
bugfix/threading-concurrency
Sep 24, 2026
Merged

gmmcosta15 merged 18 commits into
devfrom
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 sendEvent → postEvent 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.

@HugoCLSC

Copy link
Copy Markdown
Member

Solid PR, solves a bunch of probable issues

@gmmcosta15
gmmcosta15 merged commit 2dc7af0 into dev Sep 24, 2026
8 checks passed
@gmmcosta15
gmmcosta15 deleted the bugfix/threading-concurrency branch September 24, 2026 09:16
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