-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support --segfault-retry=3
#1854
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7255061
chore: wip
antfu 93bb8a2
chore: update
antfu fbe846e
Merge remote-tracking branch 'origin/main' into feat/cli-wrapper
antfu d1edf89
chore: feat update
antfu 367be72
chore: cleanup package
antfu c88cf39
chore: retry on ci
antfu 3aa503b
Merge remote-tracking branch 'origin/main' into feat/cli-wrapper
antfu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,9 @@ on: | |
branches: | ||
- main | ||
|
||
env: | ||
VITEST_SEGFAULT_RETRY: 3 | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* eslint-disable no-console */ | ||
/** | ||
* Wrapper of the CLI with child process to manage segfaults and retries. | ||
*/ | ||
import { fileURLToPath } from 'url' | ||
import c from 'picocolors' | ||
import { execa } from 'execa' | ||
|
||
const ENTRY = new URL('./cli.mjs', import.meta.url) | ||
|
||
interface ErrorDef { | ||
trigger: string | ||
url: string | ||
} | ||
|
||
// Node errors seen in Vitest (vitejs/vite#9492) | ||
const ERRORS: ErrorDef[] = [ | ||
{ | ||
trigger: 'Check failed: result.second.', | ||
url: 'https://github.com/nodejs/node/issues/43617', | ||
}, | ||
{ | ||
trigger: 'FATAL ERROR: v8::FromJust Maybe value is Nothing.', | ||
url: 'https://github.com/vitest-dev/vitest/issues/1191', | ||
}, | ||
{ | ||
trigger: 'FATAL ERROR: v8::ToLocalChecked Empty MaybeLocal.', | ||
url: 'https://github.com/nodejs/node/issues/42407', | ||
}, | ||
] | ||
|
||
async function main() { | ||
// default exit code = 100, as in retries were exhausted | ||
const exitCode = 100 | ||
let retries = 0 | ||
const args = process.argv.slice(2) | ||
|
||
if (process.env.VITEST_SEGFAULT_RETRY) { | ||
retries = +process.env.VITEST_SEGFAULT_RETRY | ||
} | ||
else { | ||
for (let i = 0; i < args.length; i++) { | ||
if (args[i].startsWith('--segfault-retry=')) { | ||
retries = +args[i].split('=')[1] | ||
break | ||
} | ||
else if (args[i] === '--segfault-retry' && args[i + 1]?.match(/^\d+$/)) { | ||
retries = +args[i + 1] | ||
break | ||
} | ||
} | ||
} | ||
|
||
retries = Math.max(1, retries || 1) | ||
|
||
for (let i = 1; i <= retries; i++) { | ||
if (i !== 1) | ||
console.log(`${c.inverse(c.bold(c.magenta(' Retrying ')))} vitest ${args.join(' ')} ${c.gray(`(${i} of ${retries})`)}`) | ||
await start(args) | ||
if (i === 1 && retries === 1) { | ||
console.log(c.yellow(`It seems to be an upstream bug of Node.js. To improve the test stability, | ||
you could pass ${c.bold(c.green('--segfault-retry=3'))} or set env ${c.bold(c.green('VITEST_SEGFAULT_RETRY=3'))} to | ||
have Vitest auto retries on flaky segfaults.\n`)) | ||
} | ||
} | ||
process.exit(exitCode) | ||
} | ||
|
||
main() | ||
|
||
async function start(args: string[]) { | ||
const child = execa('node', [fileURLToPath(ENTRY), ...args], { | ||
reject: false, | ||
all: true, | ||
stderr: 'pipe', | ||
stdout: 'inherit', | ||
stdin: 'inherit', | ||
}) | ||
child.stderr?.pipe(process.stderr) | ||
const { all: output = '' } = await child | ||
|
||
for (const error of ERRORS) { | ||
if (output.includes(error.trigger)) { | ||
if (process.env.GITHUB_ACTIONS) | ||
console.log(`::warning:: Segmentfault Error Detected: ${error.trigger}\nRefer to ${error.url}`) | ||
|
||
const RED_BLOCK = c.inverse(c.red(' ')) | ||
console.log(`\n${c.inverse(c.bold(c.red(' Segmentfault Error Detected ')))}\n${RED_BLOCK} ${c.red(error.trigger)}\n${RED_BLOCK} ${c.red(`Refer to ${error.url}`)}\n`) | ||
return | ||
} | ||
} | ||
|
||
// no segmentfault found | ||
process.exit(child.exitCode!) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/usr/bin/env node | ||
import './dist/cli.mjs' | ||
import './dist/cli-wrapper.mjs' |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't it hurt performance for "--segfault-retry=1" that we always starts a child process? Shouldn't we just import
./cli.mjs
in this case?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, but we can't show useful error message that way 🤔
I guess it's ok for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't count how many times we invoke
vitest
in our test, but at the high level, it doesn't make CI time increase. Using this would allow us to provide information about the segfault reasoning and issue link.