Skip to content

fork-follow.sh leaks one mktemp -d folder per call outside Actions (about 4,000 a day on a dev machine) #473

Closed

Description

@scuttletoby

What happens

.github/scripts/fork-follow.sh line 51 makes its log folder like this and never removes it:

logs="${RUNNER_TEMP:-$(mktemp -d)}"

On Actions RUNNER_TEMP is set, so nothing leaks there. Anywhere else (a developer or agent running the script tests) every call leaves one /tmp/tmp.XXXXXXXXXX folder holding fetch.log, schema-check.log, seam-check.log, rebase.log, triggers.log, paths and workflow.yml. The script has an ERR trap but no EXIT trap.

fork-follow.test.sh cleans its own $root with a trap, but it calls fork-follow.sh many times and those folders land outside $root. One run of the script tests leaves about 230 folders.

Measured on one dev machine

  • 25,458 tmp.* folders in /tmp after 7 days, about 4,000 a day, 0.7 GB. They are small, but /tmp gets slow to list.
  • Of the 2,071 made in the last day: 2,025 hold the fork-follow log names above, 18 hold an unpacked t3-<version>-<platform> folder (second leak, below), 28 are empty (source not proven; likely a run that stopped before its first log).

Second, smaller leak

fork-release.sh, cmd_check_archives (line 251): work="$(mktemp -d)" is removed on line 267, but the two die calls between them exit first, so every refused archive leaves its unpacked folder behind. The tests exercise exactly those refusals.

Suggested fix

  1. fork-follow.sh: keep RUNNER_TEMP as it is; when it is unset, own the folder and remove it on exit.

    if [[ -n "${RUNNER_TEMP:-}" ]]; then
      logs="$RUNNER_TEMP"
    else
      logs="$(mktemp -d "${TMPDIR:-/tmp}/fork-follow.XXXXXX")"
      trap 'rm -rf "$logs"' EXIT
    fi

    Every use of $logs is inside the script (the reports are written from the logs before it exits), so nothing reads the folder afterwards.

  2. fork-release.sh cmd_check_archives: remove $work on every path, for example one folder for the whole function with an EXIT trap, or rm -rf "$work" before each die.

  3. Tests: export TMPDIR="$root" at the top of fork-follow.test.sh and fork-release.test.sh, so anything a script still leaks lands in the folder the test already removes. Add one check to each that a call leaves no new entry in $TMPDIR (count before and after), for a passing and a refused run.

State questions

  • Runs again: nothing accumulates; each call removes its own folder.
  • Stops half-way (set -e, die, a refusal): the EXIT trap still runs. A kill -9 leaves one folder, now named fork-follow.*, so a retention rule can match it by name instead of the catch-all tmp.*.
  • Old state: the folders already leaked are not touched by this fix; they need a one-off cleanup by age.

General vs project

General: these are fork tooling scripts with no project facts in them. Nothing project-specific is needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions