Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/secrets/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export async function runSecret(
let total = 0;
let failure: SecretCode | undefined;
let killTimer: ReturnType<typeof setTimeout> | undefined;
let stopRequested = false;
const child = spawn(executor.executable, [executor.entry], {
cwd: executor.cwd,
shell: false,
Expand All @@ -62,12 +63,17 @@ export async function runSecret(
try {
process.kill(-child.pid, sig);
} catch (error) {
if ((error as NodeJS.ErrnoException).code !== 'ESRCH')
failure = 'EXECUTOR_FAILED';
const errno = (error as NodeJS.ErrnoException).code;
// macOS reports EPERM for a group whose leader exited but is not yet reaped.
const gone =
errno === 'ESRCH' ||
(errno === 'EPERM' && (stopRequested || done));
if (!gone) failure ??= 'EXECUTOR_FAILED';
}
};
const stop = (why: SecretCode) => {
if (done) return;
if (done || stopRequested) return;
stopRequested = true;
failure ??= why;
child.stdin.destroy();
kill('SIGTERM');
Expand Down
21 changes: 21 additions & 0 deletions tests/secrets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,27 @@ describe.skipIf(process.platform !== 'darwin')(
});
},
);
it('keeps the stop reason when a later group signal reports EPERM', async () => {
await writeFile(
path.join(root, 'package/main.cjs'),
"process.stdout.write('x'.repeat(100000));setInterval(()=>{},1000)",
);
await setup();
const kill = process.kill.bind(process);
let groupSignals = 0;
// macOS returns EPERM when signalling a group whose leader exited but is not yet reaped.
vi.spyOn(process, 'kill').mockImplementation((pid, signal) => {
if (typeof pid === 'number' && pid < 0 && ++groupSignals > 1) {
throw Object.assign(new Error('kill EPERM'), { code: 'EPERM' });
}
return kill(pid, signal);
});
expect(await run()).toMatchObject({
status: 'outcome_unknown',
code: 'OUTPUT_LIMIT',
});
expect(groupSignals).toBeGreaterThan(1);
});
it('honors cancellation before decrypting', async () => {
await setup();
const c = new AbortController();
Expand Down
Loading