Skip to content

fix: add retry logic for HUD startup to handle race conditions#965

Merged
LexiconCode merged 1 commit into
dictation-toolbox:masterfrom
amirf147:fix/hud-startup-retry
May 16, 2026
Merged

fix: add retry logic for HUD startup to handle race conditions#965
LexiconCode merged 1 commit into
dictation-toolbox:masterfrom
amirf147:fix/hud-startup-retry

Conversation

@amirf147
Copy link
Copy Markdown
Contributor

Fix HUD connection race condition on cold boot

Description

I've updated HudPrintMessageHandler to include a retry loop when establishing the initial connection to the HUD process. Instead of failing instantly on the first ping, the handler will now poll for a connection up to 10 times with a 0.5-second delay. The hope is that this gives the OS enough time to spin up the background process and bind the port before Caster gives up and flags the HUD as inactive.

Related Issue

Fixes #920

Motivation and Context

After running into this issue and discussing it with an LLM, I suspect this might be a race condition occurring on a cold startup. It seems like when running Caster for the first time after a boot, start_hud launches the HUD via subprocess.Popen, but the main Caster thread continues executing and attempts to ping the HUD before the OS has fully opened the port.

This appears to result in the [WinError 10061] Connection Refused error, leaving a blank white HUD window. Restarting Caster usually bypasses the error, likely due to OS caching making the process load much faster the second time around. This fix is an attempt to ensure Caster gracefully waits for the HUD to wake up before throwing the error.

hud-error

How Has This Been Tested

Tested by observing Caster's initial startup immediately following a full system reboot. It appears that the new polling loop successfully catches the delay, waits for the port to open, and connects to the HUD GUI, avoiding the instant [WinError 10061] failure I was seeing previously.

Types of changes

  • Bug fix (non-breaking change which fixes an issue or bug)

Checklist

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • I have checked that my code does not duplicate functionality elsewhere in Caster.
  • My code implements all the features I wish to merge in this pull request.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests pass.

Maintainer/Reviewer Checklist

  • Basic functionality has been tested and works as claimed.
  • New documentation is clear and complete.
  • Code is clear and readable.

@amirf147 amirf147 marked this pull request as ready for review May 16, 2026 18:57
Copy link
Copy Markdown
Member

@LexiconCode LexiconCode left a comment

Choose a reason for hiding this comment

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

Thank you. I really appreciate these pull requests! Every bit helps.

@LexiconCode LexiconCode merged commit c1e9a85 into dictation-toolbox:master May 16, 2026
3 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.

HUD doesn't load on computer startup.

2 participants