Skip to content

fix: not exit with code 1 when unexpectedly exited during teardown#741

Merged
9aoy merged 1 commit intomainfrom
unexpectedly-exited-when-tear-down
Dec 8, 2025
Merged

fix: not exit with code 1 when unexpectedly exited during teardown#741
9aoy merged 1 commit intomainfrom
unexpectedly-exited-when-tear-down

Conversation

@9aoy
Copy link
Copy Markdown
Collaborator

@9aoy 9aoy commented Dec 8, 2025

Summary

not exit with code 1 when unexpectedly exited during teardown.
image

Related Links

https://github.com/web-infra-dev/rspack/actions/runs/20021870432/job/57410628304

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings December 8, 2025 09:02
@netlify
Copy link
Copy Markdown

netlify bot commented Dec 8, 2025

Deploy Preview for rstest-dev ready!

Name Link
🔨 Latest commit 1196f89
🔍 Latest deploy log https://app.netlify.com/projects/rstest-dev/deploys/6936940d2802400008754014
😎 Deploy Preview https://deploy-preview-741--rstest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
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 fixes an issue where the test runner incorrectly exits with code 1 when an unexpected exit occurs during the teardown phase (after tests complete but while closing the worker pool and server). The change distinguishes between exits during test execution versus teardown, treating teardown exits as warnings rather than errors.

  • Introduces an isTeardown flag to track whether teardown has begun
  • Changes the exit handler to log a warning (yellow) instead of an error (red) during teardown and skips setting process.exitCode = 1
  • Prevents false-positive test failures caused by normal cleanup operations in the test environment

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 487 to 489
await pool.close();
await closeServer();
process.off('exit', unExpectedExit);
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

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

If pool.close() or closeServer() throws an error, the process.off('exit', unExpectedExit) cleanup won't execute, leaving the event listener attached. This could cause memory leaks or unexpected behavior. Consider wrapping the teardown operations in a try-finally block:

await run();
isTeardown = true;
try {
  await pool.close();
  await closeServer();
} finally {
  process.off('exit', unExpectedExit);
}
Suggested change
await pool.close();
await closeServer();
process.off('exit', unExpectedExit);
try {
await pool.close();
await closeServer();
} finally {
process.off('exit', unExpectedExit);
}

Copilot uses AI. Check for mistakes.
Comment on lines +465 to 489
let isTeardown = false;

const unExpectedExit = (code?: number) => {
logger.log(
color.red(
`Rstest exited unexpectedly with code ${code}, terminating test run.`,
),
);
process.exitCode = 1;
if (isTeardown) {
logger.log(
color.yellow(
`Rstest exited unexpectedly with code ${code}, this is likely caused by test environment teardown.`,
),
);
} else {
logger.log(
color.red(
`Rstest exited unexpectedly with code ${code}, terminating test run.`,
),
);
process.exitCode = 1;
}
};
process.on('exit', unExpectedExit);

await run();
isTeardown = true;
await pool.close();
await closeServer();
process.off('exit', unExpectedExit);
Copy link

Copilot AI Dec 8, 2025

Choose a reason for hiding this comment

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

The new teardown exit handling logic lacks test coverage. Consider adding tests to verify:

  1. That isTeardown = true prevents setting process.exitCode = 1 during teardown
  2. That the exit handler correctly distinguishes between exits before and after teardown begins
  3. That the exit handler is properly removed after successful teardown

This is important to prevent regressions in the fix for unexpected exit handling during teardown.

Copilot uses AI. Check for mistakes.
@9aoy 9aoy merged commit 796884e into main Dec 8, 2025
23 checks passed
@9aoy 9aoy deleted the unexpectedly-exited-when-tear-down branch December 8, 2025 09:17
@9aoy 9aoy mentioned this pull request Dec 8, 2025
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