Skip to content

Fix temp directories leaked by the update-gh-pages task (#240)#722

Merged
alexander-yevsyukov merged 4 commits into
masterfrom
claude/vibrant-heyrovsky-f88e0c
Jul 1, 2026
Merged

Fix temp directories leaked by the update-gh-pages task (#240)#722
alexander-yevsyukov merged 4 commits into
masterfrom
claude/vibrant-heyrovsky-f88e0c

Conversation

@alexander-yevsyukov

Copy link
Copy Markdown
Contributor

What

The updateGitHubPages task created the javadoc, html, and repoTemp temporary
directories (via LazyTempPath) directly under the system temp directory, with cleanup
performed only eagerly — UpdateGitHubPages.cleanup() (in a finally) and
Repository.close() (via use {}). When a build fails, or the Gradle daemon is killed,
before that cleanup runs, the directories leak permanently. File.deleteOnExit() cannot
help here: it does not delete non-empty directories, and these always are.

Fixes #240.

How

Group every such directory under one recognizable base directory
(<java.io.tmpdir>/io.spine.gradle.fs) and remove that base directory recursively via a
single JVM shutdown hook — mirroring the approach of
SpineEventEngine/base#671.

  • New SpineTempDir lazily creates the base directory and registers the shutdown hook
    exactly once (by lazy, synchronized). The hook logs to stderr if the recursive
    delete does not fully succeed, so a failed cleanup is visible rather than silent.
  • LazyTempPath now creates its directory under SpineTempDir.path
    (createTempDirectory(SpineTempDir.path, prefix)); the javadoc/html/repoTemp
    call sites are unchanged.
  • The existing eager cleanup stays the primary mechanism (it frees disk promptly in a
    long-lived daemon); the shutdown hook is the safety net.

The issue's note about "migrating it to Kotlin" is already satisfied — this code is Kotlin.
(The legacy scripts/publish-documentation/publish.sh creates a different workspace
directory and is out of scope.)

Tests

  • LazyTempPathSpec (4 tests) — directories are created on first use, under the system
    temp dir, under the io.spine.gradle.fs base dir, and all instances share one parent.
  • SpineTempDirSpec (2 tests) — SpineTempDir.path resolves to
    <java.io.tmpdir>/io.spine.gradle.fs and exists after access.

Verification

  • ./gradlew -p buildSrc build — green (whole buildSrc suite; 6/6 new fs tests pass)
    under JDK 17. (The repo root has no build task; all code lives in buildSrc.)
  • Pre-PR reviewers kotlin-engineer, spine-code-review, and review-docs — all APPROVE.

🤖 Generated with Claude Code

The `updateGitHubPages` task created the `javadoc`, `html`, and `repoTemp`
temporary directories via `LazyTempPath` directly under the system temp
directory, with cleanup performed only eagerly (`UpdateGitHubPages.cleanup()`
and `Repository.close()`). A failed build or a killed Gradle daemon leaked
them permanently. `File.deleteOnExit()` cannot help — it does not delete
non-empty directories.

Create every such directory under a shared base directory
(`<java.io.tmpdir>/io.spine.gradle.fs`) that is registered for recursive
deletion via a single JVM shutdown hook, mirroring the approach of
SpineEventEngine/base-libraries#671. The eager cleanup stays the primary mechanism;
the shutdown hook is the safety net.

Fixes #240.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses leaked temporary directories created by the updateGitHubPages pipeline by routing all LazyTempPath directories under a shared base temp directory and ensuring a JVM-shutdown cleanup safety net.

Changes:

  • Introduces SpineTempDir as a shared parent directory under java.io.tmpdir, with recursive deletion via a JVM shutdown hook.
  • Updates LazyTempPath to create its temp directories under SpineTempDir.path.
  • Adds unit tests covering the new temp directory layout and lazy creation behavior.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
buildSrc/src/main/kotlin/io/spine/gradle/fs/SpineTempDir.kt Adds shared base temp directory and shutdown-hook cleanup logic.
buildSrc/src/main/kotlin/io/spine/gradle/fs/LazyTempPath.kt Routes temp directory creation through SpineTempDir and updates KDoc.
buildSrc/src/test/kotlin/io/spine/gradle/fs/LazyTempPathSpec.kt Verifies LazyTempPath creates directories under the shared base dir.
buildSrc/src/test/kotlin/io/spine/gradle/fs/SpineTempDirSpec.kt Verifies SpineTempDir.path location and lazy directory creation.
.agents/tasks/fix-temp-dirs-update-gh-pages.md Adds the task record describing the approach, plan, and verification.

Comment thread buildSrc/src/main/kotlin/io/spine/gradle/fs/SpineTempDir.kt Outdated
Comment thread buildSrc/src/main/kotlin/io/spine/gradle/fs/SpineTempDir.kt Outdated
Comment thread buildSrc/src/main/kotlin/io/spine/gradle/fs/LazyTempPath.kt Outdated
alexander-yevsyukov and others added 2 commits June 30, 2026 18:19
- Give each JVM its own subdirectory under the `io.spine.gradle.fs` namespace
  (named after the PID), and delete only that subdirectory on shutdown. The
  shared namespace is no longer removed, so concurrent Gradle daemons can no
  longer wipe each other's in-flight temporary directories.
- Fail fast with a clear message if `java.io.tmpdir` is unset, instead of an
  opaque NPE.
- Clarify the `LazyTempPath` KDoc: cleanup is guaranteed on JVM (Gradle daemon)
  shutdown; eager task cleanup remains the primary mechanism.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@alexander-yevsyukov alexander-yevsyukov moved this from 🏗 In progress to In Review in v2.0 Jun 30, 2026
@alexander-yevsyukov alexander-yevsyukov merged commit 73d246a into master Jul 1, 2026
3 checks passed
@alexander-yevsyukov alexander-yevsyukov deleted the claude/vibrant-heyrovsky-f88e0c branch July 1, 2026 08:20
@github-project-automation github-project-automation Bot moved this from In Review to ✅ Done in v2.0 Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Fix temp. directories created by update-gh-pages script

3 participants