Skip to content

fix: explicitly close DevEngine to prevent coordinator task leaks under shared runtime#8568

Merged
hyf0 merged 2 commits intoperf/share-tokio-runtime-fixture-testsfrom
copilot/sub-pr-8567
Mar 6, 2026
Merged

fix: explicitly close DevEngine to prevent coordinator task leaks under shared runtime#8568
hyf0 merged 2 commits intoperf/share-tokio-runtime-fixture-testsfrom
copilot/sub-pr-8567

Conversation

Copy link
Contributor

Copilot AI commented Mar 6, 2026

With a shared Tokio runtime across fixture tests, drop(dev_engine) no longer cleans up background tasks — the BundleCoordinator task spawned by DevEngine::run() persists into subsequent tests since it requires an explicit shutdown signal.

Change

  • Replace drop(dev_engine) with dev_engine.close().await in run_multiple_for_dev (crates/rolldown_testing/src/integration_test.rs)
  • close() atomically marks the engine as closed, sends CoordinatorMsg::Close, invokes the closeBundle plugin hook, and awaits the coordinator handle
  • Errors are suppressed (let _ = ...) since the coordinator may have already exited in error paths — cleanup failures should not obscure the original test failure

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…ntime

Co-authored-by: hyf0 <49502170+hyf0@users.noreply.github.com>
Copilot AI changed the title [WIP] Update sharing tokio runtime across fixture tests fix: explicitly close DevEngine to prevent coordinator task leaks under shared runtime Mar 6, 2026
Copilot finished work on behalf of hyf0 March 6, 2026 15:39
@hyf0 hyf0 marked this pull request as ready for review March 6, 2026 15:57
Copilot AI review requested due to automatic review settings March 6, 2026 15:57
@hyf0 hyf0 merged commit c414b04 into perf/share-tokio-runtime-fixture-tests Mar 6, 2026
2 checks passed
@hyf0 hyf0 deleted the copilot/sub-pr-8567 branch March 6, 2026 15:57
Copy link
Contributor

Copilot AI left a comment

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 updates the HMR/dev-mode integration test harness to explicitly shut down DevEngine so that the background BundleCoordinator task doesn’t leak across tests when running under a shared Tokio runtime.

Changes:

  • Replace drop(dev_engine) with an awaited dev_engine.close() call after each dev test run.
  • Add inline comments explaining why explicit shutdown is required under a shared runtime.

Comment on lines +366 to +368
// Explicitly close the dev engine to shut down the background coordinator task.
// Without this, the coordinator task would persist across tests under the shared runtime.
let _ = dev_engine.close().await;
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

dev_engine.close().await is only reached on the happy path; earlier unwrap()/assert! calls in this loop can panic and skip this cleanup, which can still leak the coordinator task into subsequent tests under a shared runtime. Consider structuring the loop so the close is run in a guaranteed cleanup path (e.g., a guard/"finally"-style pattern) so it executes even when the test logic panics.

Copilot uses AI. Check for mistakes.
drop(dev_engine);
// Explicitly close the dev engine to shut down the background coordinator task.
// Without this, the coordinator task would persist across tests under the shared runtime.
let _ = dev_engine.close().await;
Copy link

Copilot AI Mar 6, 2026

Choose a reason for hiding this comment

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

The cleanup error from dev_engine.close().await is fully suppressed here. Since close() also runs the closeBundle plugin hook and waits for the coordinator to finish, swallowing errors can make it hard to diagnose cleanup regressions (and could leave background tasks running if Close couldn’t be sent). Consider at least emitting the error to stdout/stderr (without failing the test) so CI logs capture unexpected close failures.

Suggested change
let _ = dev_engine.close().await;
if let Err(err) = dev_engine.close().await {
eprintln!("dev_engine.close() failed during test cleanup: {err:?}");
}

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

Benchmarks Rust

  • target: perf/share-tokio-runtime-fixture-tests(7e4665b)
  • pr: copilot/sub-pr-8567(906b258)
group                                                        pr                                     target
-----                                                        --                                     ------
bundle/bundle@multi-duplicated-top-level-symbol              1.12     85.3±2.92ms        ? ?/sec    1.00     76.1±3.80ms        ? ?/sec
bundle/bundle@multi-duplicated-top-level-symbol-sourcemap    1.15     96.1±4.44ms        ? ?/sec    1.00     83.9±2.61ms        ? ?/sec
bundle/bundle@rome_ts                                        1.18    190.0±4.93ms        ? ?/sec    1.00    161.7±4.69ms        ? ?/sec
bundle/bundle@rome_ts-sourcemap                              1.20    211.8±5.29ms        ? ?/sec    1.00    176.7±3.61ms        ? ?/sec
bundle/bundle@threejs                                        1.24     93.2±4.31ms        ? ?/sec    1.00     75.1±2.89ms        ? ?/sec
bundle/bundle@threejs-sourcemap                              1.26    103.7±2.13ms        ? ?/sec    1.00     82.3±3.06ms        ? ?/sec
bundle/bundle@threejs10x                                     1.02   815.9±11.53ms        ? ?/sec    1.00   796.3±11.07ms        ? ?/sec
bundle/bundle@threejs10x-sourcemap                           1.03   937.7±13.91ms        ? ?/sec    1.00   911.2±12.32ms        ? ?/sec
scan/scan@rome_ts                                            1.02     75.8±1.91ms        ? ?/sec    1.00     74.1±2.37ms        ? ?/sec
scan/scan@threejs                                            1.04     27.4±1.80ms        ? ?/sec    1.00     26.4±0.35ms        ? ?/sec
scan/scan@threejs10x                                         1.03    265.0±6.40ms        ? ?/sec    1.00    257.3±2.55ms        ? ?/sec

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.

3 participants