Skip to content

helper: write the last log line before signalling the caller - #1137

Merged
craigds merged 2 commits into
masterfrom
cds-e2e-cleanup-race
Nov 18, 2026
Merged

craigds merged 2 commits into
masterfrom
cds-e2e-cleanup-race

Conversation

@craigds

@craigds craigds commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Description

The e2e test (helper) step fails intermittently in its cleanup, for example in this run:

rm: cannot remove '/tmp/kart-e2e.5xTMN2': Directory not empty

The e2e script puts KART_HELPER_LOG inside its temp folder and removes the folder on exit. After running a command, the helper's forked child sent SIGALRM to the caller and then wrote bye(0) to the log. The caller exits on SIGALRM, so the script's rm -rf could run while that last write re-created the log file. In the failing run, the helper log ends with the last child's sending SIGALRM line and no bye(0), so the cleanup had already read the log when the child wrote its final line.

The child now writes its final log line before signalling, and exits straight after.

Not covered by an automated test, because the window is only a few microseconds: 200 runs of a command through the helper, each followed immediately by removing the log directory, never hit it. With a temporary 50 ms sleep added right after the helper sends SIGALRM, the same loop gives:

  • before this change: the log file re-appeared after the caller returned in 50 of 50 runs;
  • after this change: 0 of 50.

The e2e script passes with and without the helper.

Related links:

Checklist:

  • Have you reviewed your own change?
  • Have you included test(s)?
  • Have you updated the changelog?

Claude session ID: 389a86fe-c780-459f-81e3-70b768e03b1b

The caller exits as soon as it gets SIGALRM, and whatever ran it may
then remove the log file's directory. Writing bye(0) after the signal
could re-create the log file mid-removal, which made the e2e test's
cleanup fail intermittently with 'Directory not empty'.
@craigds
craigds marked this pull request as ready for review November 18, 2026 21:18
Copilot AI lite review requested due to automatic review settings November 18, 2026 21:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

A moderate issue remains in kart/helper.py because the ProcessLookupError path logs after signalling, allowing cleanup to race the write and potentially raise FileNotFoundError.

1 open issue
What changed in this PR

Updates helper shutdown ordering so the final log entry is written before signaling the caller, preventing cleanup from racing with a late log-file write.

Changes:

  • Combines the final bye(0) marker with the pre-signal log entry.
  • Exits the helper child immediately after the signalling attempt.
File Description
kart/​helper.py Reorders final helper logging and child termination around SIGALRM to avoid recreating the log file during temporary-directory cleanup.

Review effort: Lite

Comment thread kart/helper.py Resolved
Its cleanup may be running too, so the write could still race it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain, and the change directly addresses the helper cleanup race by recording the final log message before signaling the caller.

No open issues 🎉

1 resolved since last review

Review effort: Lite

@craigds
craigds merged commit 4c23fe9 into master Nov 18, 2026
33 checks passed
@craigds
craigds deleted the cds-e2e-cleanup-race branch November 18, 2026 23:41
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