Skip to content

Clean up the runner's temporary directories - #2763

Merged
natebosch merged 13 commits into
masterfrom
temp-directory-cleanup
Sep 24, 2026
Merged

natebosch merged 13 commits into
masterfrom
temp-directory-cleanup

Conversation

@natebosch

@natebosch natebosch commented Sep 19, 2026 •

Copy link
Copy Markdown
Member

Stacked on #2765, which refactors the signal handling this builds on.

Temporary directories were created all over the place - browser profiles,
compiler output, the VM platform's sockets - each with its own
Directory.systemTemp.createTempSync call, and nothing deleted most of them. A
run leaves everything it created behind for the OS to clean up whenever it gets
around to it.

They are now all created under a single dart_test. directory, so cleanup is
one recursive delete. Runner.close does that delete once every platform has
been closed, which also covers a run interrupted with a single Control-C, since
that shuts down gracefully.

A second signal skips the graceful shutdown, so the handler added in #2765
deletes the directory synchronously before it exits.

This also replaces createTempDir, which returned a path, with
createTempDirectory, which returns a Directory. It takes a prefix so the
directories nested under the shared root stay distinguishable, matching the
names the call sites passed when they used dart:io directly.

The VM platform's per-suite socket directory moves out from under the platform's
own temp directory and becomes a sibling of it, which keeps the unix socket path
within the ~104 byte limit it has on some platforms.

"Press Control-C again to terminate immediately" now performs a synchronous
recursive delete before exiting, which is not free for the large directories
that motivated this.

Temporary directories were created all over the place - browser
profiles, compiler output, the VM platform's sockets - each with its own
`Directory.systemTemp.createTempSync` call, and nothing deleted most of
them. A run would leave everything it created behind for the OS to clean
up whenever it got around to it.

Create them all under a single `dart_test.` directory instead, so
cleanup is one recursive delete. `Runner.close` does that delete once
every platform has been closed, which also covers a run that was
interrupted with a single Control-C, since that shuts down gracefully.

A second signal skips the graceful shutdown, so handle it directly:
delete the directory synchronously and exit. This requires leaving the
signal subscription active after the first signal, where previously it
was cancelled and the second signal was left to Dart's default handler.
The exit code is the same as the shell reports for a process killed by
the signal, though the process now exits normally with that code rather
than being killed by the signal.

This also replaces `createTempDir`, which returned a path, with
`createTempDirectory`, which returns a `Directory`, removing a
distinction without a difference between the two names.
@natebosch
natebosch requested a review from a team as a code owner September 19, 2026 02:14
@github-actions

github-actions Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

PR Health

Changelog Entry ✔️
Package Changed Files

Changes to files need to be accounted for in their respective changelogs.

This check can be disabled by tagging the PR with skip-changelog-check.

@natebosch
natebosch marked this pull request as draft September 19, 2026 02:22
Keep the signal subscription active during graceful shutdown so a second
signal can be handled explicitly in Dart before exiting with the signal
exit code, and cancel the subscription in the finally block once the
runner closes. Add logic to determine the exit code that would have been
used by the Dart VM when it was handling the second signal.
This prepares for an upcoming change which improves temporary directory
cleanup during shutdown.

The `runTests` and `completeShutdown` methods are unused externally, so
remove and inline them. Move the `signalSubscription` global variable to
a local variable in the main method. Drop the global `isShutdown`
variable. Reset `_stdinLines` in `cancelStdinLines` so it is safe to
call more than once.

Closes #1615
Take the signal handling refactor from the base branch, keeping only the
temporary directory cleanup on top of it:

* The signal subscription is now a late final local cancelled by the
  listener itself, so the second signal handler only adds the synchronous
  delete of the temporary directory before exiting.
* Keep the base branch's exit code mapping and its version of the
  'runs tests successfully more than once' runner test, which now calls
  'main' twice instead of the removed 'runTests'.
@natebosch
natebosch changed the base branch from master to refactor-signal-handling September 23, 2026 23:28
@natebosch
natebosch added this pull request to stack #2769 September 23, 2026 23:53
@natebosch
natebosch marked this pull request as ready for review September 23, 2026 23:53
The per-suite directory holding the unix socket for `exe` and `cli`
suites was still created with `dart:io` directly, nested inside the VM
platform's own temp directory. Create it with `createTempDirectory` like
every other temp directory, as a sibling of the platform directory
rather than a child of it.

The path is now one level shallower than before, which leaves enough
room under the ~104 byte unix socket path limit to restore the readable
`exec.`/`socket.sock` names.

These directories are now deleted with the shared root in
`Runner.close`, rather than by `VMPlatform.close`, which happens at
effectively the same point in the run.
Base automatically changed from refactor-signal-handling to master September 24, 2026 19:41
@natebosch
natebosch merged commit 603e5ec into master Sep 24, 2026
118 of 120 checks passed
@natebosch
natebosch deleted the temp-directory-cleanup branch September 24, 2026 21:00
copybara-service Bot pushed a commit to dart-lang/sdk that referenced this pull request Oct 6, 2026
Revisions updated by `dart tools/rev_sdk_deps.dart`.

native (https://github.com/dart-lang/native/compare/f628b26..27f7678):
  27f767827  Mon Sep 28 14:51:28 2026 +0200  Daco Harkes  [hooks_runner] Remove `KernelAssets` and `Target` (dart-lang/native#3703)
  ddc7d6deb  Mon Sep 28 05:40:03 2026 +0200  Jakob Kordež  [ffigen] Skip typedefs to function pointers with unsupported parameter types (dart-lang/native#3694)
  177d283d9  Mon Sep 28 04:30:28 2026 +0200  Jakob Kordež  [ffigen] Generate bindings for C++ enums, structs and unions nested in namespaces and records (dart-lang/native#3644)
  5ee8f67d8  Mon Sep 28 11:39:14 2026 +1000  Liam Appelbe  [objective_c] Clarify block isolate scoping (dart-lang/native#3692)
  25f090116  Fri Sep 25 12:09:12 2026 +1000  Liam Appelbe  [ffigen][jnigen] Deprecate YAML config (dart-lang/native#3654)
  8364413eb  Fri Sep 25 10:09:50 2026 +1000  Liam Appelbe  [jnigen] Document nullability (dart-lang/native#3690)
  e8d518574  Thu Sep 24 18:02:46 2026 +1000  Liam Appelbe  [ffigen] Code snippet-ify ffigen and objective_c (dart-lang/native#3685)
  663385955  Thu Sep 24 03:21:53 2026 +0300  Manar Elhabbal  [ffigen] prevent setting both cpp and objectiveC in ffigenerator (dart-lang/native#3687)
  1cf40952a  Thu Sep 24 09:27:09 2026 +1000  Liam Appelbe  [objective_c] Remove arm64e build hack (dart-lang/native#3680)
  c44550b6e  Wed Sep 23 13:01:33 2026 +0200  Simon Binder  [web_assets] Scaffold package (dart-lang/native#3610)
  57b4bad69  Wed Sep 23 16:21:27 2026 +1000  Liam Appelbe  [swift2objc] Code snippet-ify swift2objc (dart-lang/native#3684)
  5cee1d0be  Wed Sep 23 10:16:29 2026 +0530  Rachit Vikram Singh  [ffigen] Add Input.appendCompilerOptions to append clang args to defaults (`#3630`) (dart-lang/native#3676)
  225a648df  Wed Sep 23 14:37:13 2026 +1000  Liam Appelbe  [jnigen] Code snippet-ify jnigen and co (dart-lang/native#3641)
  2030decf9  Wed Sep 23 13:51:24 2026 +1000  Liam Appelbe  [infra] Move snippets_tool to its own package (dart-lang/native#3683)
  6fa2beea2  Wed Sep 23 12:14:28 2026 +1000  Liam Appelbe  [objective_c] Revert `#3664` (dart-lang/native#3681)
  ed7605f8a  Tue Sep 22 12:03:22 2026 +0530  Sivapriya  [jni] Add deep conversion utils (dart-lang/native#3635)
  8574b7422  Tue Sep 22 08:31:11 2026 +0200  Lukas Klingsbo  [ffigen] Allow package:cli_util 0.5.x and 0.6.x (dart-lang/native#3673)

test (https://github.com/dart-lang/test/compare/9946c95..4f92d53):
  4f92d530  Fri Sep 25 16:46:22 2026 -0700  Nate Bosch  Unskip a test on windows (dart-lang/test#2772)
  7fb84866  Fri Sep 25 14:52:39 2026 -0700  Nate Bosch  Bundle skips at the end of the GitHub reporter (dart-lang/test#2768)
  603e5ec5  Thu Sep 24 14:00:41 2026 -0700  Nate Bosch  Clean up the runner's temporary directories (dart-lang/test#2763)
  4bf04d90  Thu Sep 24 12:41:15 2026 -0700  Nate Bosch  Refactor signal handling in executable.dart (dart-lang/test#2765)
  2c660a84  Tue Sep 22 15:33:34 2026 -0700  Nate Bosch  Regenerate mono_repo output (dart-lang/test#2767)

tools (https://github.com/dart-lang/tools/compare/3614ce0..d87eaf7):
  d87eaf79  Thu Sep 24 08:31:33 2026 -0700  Kevin Moore  fix(benchmark_harness): migrate subprocess spawning to package:cli_util (dart-lang/tools#2585)
  8ccf8ccf  Wed Sep 23 05:09:10 2026 +0530  Aman Maurya  [string_scanner] Extract a mixin for LineScanner and deduplicate eager scanning logic (dart-lang/tools#2569)
  afcdd6d9  Tue Sep 22 15:38:07 2026 +0200  Morgan :)  Document that watch events converge on filesystem state. (dart-lang/tools#2607)
  f2157cbc  Tue Sep 22 04:52:58 2026 +0300  Hasan Armoush  [code_builder] Add null-aware cascades, cascade index, and fluent cascade helpers (dart-lang/tools#2540)

web (https://github.com/dart-lang/web/compare/e5c6c02..ec71a4c):
  ec71a4c  Mon Sep 28 10:07:01 2026 -0700  Kevin Moore  [js_interop_gen] Require `code_builder: ^4.12.0` and update golden headers (dart-lang/web#576)

[email protected]

Change-Id: I766bc5b2b1297e3251990821bb73387ba685e39b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/556320
Commit-Queue: Nate Bosch <[email protected]>
Reviewed-by: Brian Quinlan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants