Skip to content
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

Spawned child process not killed on GitHub Actions #11892

Open
karlhorky opened this issue Jun 15, 2024 · 3 comments
Open

Spawned child process not killed on GitHub Actions #11892

karlhorky opened this issue Jun 15, 2024 · 3 comments
Labels
bug Something isn't working needs triage

Comments

@karlhorky
Copy link

karlhorky commented Jun 15, 2024

What version of Bun is running?

1.1.13+bd6a60512

What platform is your computer?

Darwin 23.5.0 arm64 arm

What steps can reproduce the bug?

  1. Create a GitHub Actions workflow with a Bun script index.ts
  2. In index.ts, create a yarn run dev child process with spawn() and use .kill() on that child process
  3. Observe that the child process is still running

Reproduction repo with GitHub Actions workflow:

What is the expected behavior?

childProcess.kill() kills process instantly on GitHub Actions

Locally, this works:

$ bun index.ts
1718467629038 childProcess1 started with PID 32286
1718467629046 Sleeping for 2 seconds...
1718467630077 childProcess1 exited with exit code 1
1718467630077 Waiting for stdoutPromise to resolve (hangs on CI)...
1718467630077 childProcess2 started with PID 32293
1718467630078 childProcess2 exited with exit code 143

What do you see instead?

childProcess.kill() does not kill the process on GitHub Actions

On GitHub Actions, it hangs on waiting for the promise

$ bun index.ts
1718467554080 childProcess1 started with PID 1828
1718467554083 Sleeping for 2 seconds...
1718467555094 childProcess1 exited with exit code 1
1718467555094 Waiting for stdoutPromise to resolve (hangs on CI)...
Error: The action 'Run script' has timed out after 1 minutes.

Additional information

I found some issues which relate to some of the same things over here:

Also, some discussion about how GitHub Actions terminates child processes differently:

@karlhorky karlhorky added bug Something isn't working needs triage labels Jun 15, 2024
@karlhorky
Copy link
Author

karlhorky commented Jun 15, 2024

Workaround 1

Through some trial and error, I found that running killall node causes the process to finish and the stdout to be read:

+import { $ } from 'bun';

// ...

-childProcess1.kill();
+await $`killall node`;

I also used this as a workaround before, to avoid the Cypress action not shutting down a dev server:

@karlhorky
Copy link
Author

karlhorky commented Jun 15, 2024

Workaround 2

Changing the packageManager field in package.json to [email protected] also seems to work around the issue:

{
-  "packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
+  "packageManager": "[email protected]"
}

Successful workflow run: https://github.com/karlhorky/repro-bun-spawn-kill-fails-on-github-actions/actions/runs/9529280612

It fails with either packageManager set to yarn@<version> or no packageManager field in package.json

Maybe this is related to Corepack on GitHub Actions?

@karlhorky
Copy link
Author

The longer I look at this issue, the less it looks directly related to Bun.

But it would be nice for Bun to have identical behavior with spawning + killing child processes on a local machine and GitHub Actions... 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant