mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-08 12:57:46 +00:00
Remove `--forceExit` and wait for the child `vc dev` process to close before continuing. Listen to the `'close'` event instead of `'exit'` to ensure stdio has been flushed and closed before continuing. Some tests cause `vc dev` to spawn child processes that in turn spawn nested child processes that do not exit when the parent exits, so a `nukeProcessTree()` helper was added to ensure all spawned processes are cleaned up. Furthermore, some of the nested child processes don't respond well to `SIGTERM` and we need to use `SIGKILL` if `SIGTERM` doesn't do the job. I uncovered a larger issue exposed by removing the `--forceExit` flag. The go builder uses `go run` to build and run the go-based serverless function. Turns out that `go run` will build the executable, then spawn it with a parent process id (ppid) of `1` (launchd) on macOS. This means that the go serverless function executable is not detected as a child process of `vc dev` and won't be cleaned up, yet has inherited `stdout` and `stderr` keeping Jest alive. The solution is to explicitly `go build` the serverless executable, then run it. ### 📋 Checklist <!-- Please keep your PR as a Draft until the checklist is complete --> #### Tests - [x] The code changed/added as part of this PR has been covered with tests - [x] All tests pass locally with `yarn test-unit` #### Code Review - [ ] This PR has a concise title and thorough description useful to a reviewer - [ ] Issue from task tracker has a link to this PR Co-authored-by: Sean Massa <EndangeredMassa@gmail.com>