Skip to content

plugin: give each thread its own temporary launcher file - #334

Open
Saksham Uboweja (SakshamUboweja) wants to merge 5 commits into
microsoft:mainfrom
SakshamUboweja:fix/launcher-thread-race
Open

Saksham Uboweja (SakshamUboweja) wants to merge 5 commits into
microsoft:mainfrom
SakshamUboweja:fix/launcher-thread-race

Conversation

@SakshamUboweja

Copy link
Copy Markdown
Collaborator

test_gateway_and_cron_sessions_in_two_repositories_fold_apart_through_the_real_dispatcher fails now and then on Windows (main on Nov 20, runs 44647406663 and 44646610551; #333 today), each time with an errors.log line about te\bin\te.json.

Cause. A Hermes gateway runs every session's hooks as threads of one process. ensure_launcher named its temporary file by the process id alone, so sessions whose first prompts wrote bin/te and bin/te.json together shared one temporary file: the first rename took it and the others failed (FileNotFoundError). On Windows, two threads replacing the same launcher also collide (PermissionError).

Fix (plugin/paths.py)

  • the temporary file is named by process and thread
  • the rename goes through store._replace, the Windows retry the store already uses
  • the temporary file is removed when a write fails

Test. test_windows_launcher.py holds four writers between write and rename, then lets them go: on main three of four fail, with the fix none do.

Checked on Windows (fork CI, Python 3.13 / 3.10), four threads writing the launcher at once, 300 times:

runs with an error
main 249 / 236
main + retry only 272 / 255
per-thread name only 238 / 261
this change 0 / 0

The Hermes test itself, 100 runs each: main failed 4 / 2, this change 0 / 0. Linux passes before and after.

A Hermes gateway runs every session's hooks as threads of one process.
The launcher's temporary file was named by the process alone, so
sessions whose first prompts wrote bin/te and bin/te.json together
shared one file: the first rename took it and the others failed, each
failure a line in errors.log. Name it by the thread too, and replace
through the store's Windows retry, since Windows refuses to replace a
file another thread is reading or replacing.
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