Repository navigation
fix(dev): stop the app's services before exiting, so Ctrl-C under npm frees their ports - #424
Conversation
Ctrl-C in a terminal sends SIGINT to the whole foreground process group. Under `npm run` or `npx`, npm also forwards the SIGINT it receives to `prisma`, so `prisma dev` gets a second SIGINT a few milliseconds after the first. The CLI engine treats a second signal as a request to exit at once, so `prisma dev` exited 130 before its stop request reached the emulators, and the app's services kept their ports. While a foreground session is live, an exit hook now stops the app before the process exits. An exit hook cannot await, so the local target runs a small program, stop-app-main, with spawnSync; it does what stopApp() does. The hook is removed once stop() finishes, so a normal Ctrl-C stops the app once. Found by the getting-started nightly (prisma/getting-started-eval#32). Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
|
Caution Gizmo failed to process the last GitHub event for this pull request: This suspended workflow run was already resumed by another caller. Workflow "guardrail-lifecycle" run "1cb3dcb6-87f4-4eef-aa7f-90e7934884dd" moved from "suspended" to "running" before this resume could claim it. Only one resume() call may continue a given suspension; re-read the run state before resuming again. Open findings: none Change walkthroughUnder Core interface (app-config.ts) — CLI (execute-dev.ts) — the hook is registered only after the foreground session is fully handed over (the detached early-return path never registers it), iterates all attachments with optional calls, and is removed both when Local target — Tests — local-dev-interrupt.integration.ts runs the installed Scope — the guides already document the restored contract ( |
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
commit: |
…over session in the test The stop that runs as `prisma dev` exits threw away the result of the stop-app-main program, so a timeout left the app running with no message. It now prints "The app could not be stopped: <why>. Run `prisma dev stop`." when the program fails, times out, or exits non-zero. The interrupt integration test now ends a `prisma dev` that a failure left running before it tears down the emulators, so a hung session cannot hold the fixture's ports for the next run. Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
…ps-services-abcbbd
Brings in #424 (prisma dev stops services before exiting), #426 (deploy copies no local value to platform variables), #429 and the v0.39.0 release. #426 carried the deploy preflight's findings to the Alchemy child in PRISMA_COMPOSER_PREFLIGHT_FINDINGS. Deploy now runs in process, so the findings reach lower() as a value, LowerOptions.findings, and that environment variable and its reader are gone. prisma deploy repeats the list of platform variables with no value at the end of its human output, as the child's report did on main. This branch's ADR-0064 becomes ADR-0065, since main owns ADR-0064. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: willbot <[email protected]> Signed-off-by: Will Madden <[email protected]>
Summary
Run the app that
create-prismamakes, press Ctrl-C, then check its port:The decision: while
prisma devruns in the foreground, it registers a process exit hook that stops the app's services. That hook runs even whenprisma devis forced to exit. Today, a forced exit cuts the stop short.What
prisma devpromisesprisma devruns each of the app's services and databases on local emulators: long-lived background programs on this machine that stand in for Prisma Cloud. The emulators outliveprisma dev, but the app's processes should not.prisma dev --helpsays: "Endingprisma devstops its services and database servers; data and ports are kept." When Ctrl-C arrives,prisma devsends the emulators a stop request and waits for it to finish.Why the stop was cut short
Pressing Ctrl-C sends SIGINT to every process in the terminal's foreground process group,
prismaincluded. Whenprismaruns undernpm runornpx, npm is in that group too, and npm forwards the SIGINT it received to its child. Soprismagets two SIGINTs about 3 ms apart.prismais built on the Prisma CLI engine (@prisma/cli-engine, from prisma/prisma-cli). Its rule is that the first signal asks the command to clean up, and a second signal means "exit now": it callsprocess.exit(130). Under npm, that second signal arrives before the stop request has reached the emulators.prisma devprints the stopping step and exits 130, and the app's process (bun bootstrap.js, a child of the compute emulator) keeps its port. In the original report it was still listening 50 seconds later. Sending SIGINT toprismaalone works, because only one signal arrives.The getting-started nightly found this (prisma/getting-started-eval#32). Its PostgreSQL quickstart script stops
npm run dev:composerwith Ctrl-C, then starts a plain Node server on port 3000, which failed withEADDRINUSE. Seen withprisma8.0.0-rc.28,@prisma/composer0.35.0, macOS and Node 26.8.How the exit hook stops the app
A
process.on('exit')hook runs whenprocess.exit()is called, but it cannot wait for anything asynchronous. The normal stop is a series of HTTP requests, so the hook runs a small program instead,stop-app-main, withspawnSync. That program calls the samestopAppInstancesfunction as the normal stop.prismaexits only after the services and database servers have stopped, so the port is free by the time the shell prompt returns.execute-dev.tsregisters the hook once a foreground session is ready. It removes the hook when the normal stop finishes, so an ordinary Ctrl-C stops the app once. A--detachsession registers no hook, because it is meant to leave the app running.LocalTargetAttachmentinapp-config.ts) gains an optionalstopAppBeforeExit(). The Prisma Cloud target implements it inattach.ts.stop-app-main.tsis the program.@prisma/composer-prisma-cloudpublishes it as./local-target/stop-app-main, next to the emulator programs, so an installed app can find it.prismafrom exiting.Testing performed
New
local-dev-interrupt.integration.tsdoes what the terminal and npm do:prisma devagainst the local-dev fixture in its own process group.prisma.Without the hook, the test fails with "service process 9118 is gone". With the hook it passes. Its log shows the stopping step starting but never finishing, so the exit hook did the stop.
These passed:
pnpm build, typecheck and unit tests for core, cli, local-target, composer-cli and prisma-cloud,pnpm lint:deps,pnpm lint:castsand biome. The one exception is the@internal/prisma-cloudtests that start Postgres. They failed on my machine withshmget: No space left on device, which means the machine had run out of shared memory. CI runs them.I did not rerun the
create-prismaapp against this branch. The integration test uses the same installedprismaand sends the same two signals.Alternatives considered
prisma devprocess dies. This would also coverkill -9. But the emulators would then need to know which session owns each app. The local-dev design says the session owns no processes and that a killed session leaves the app forprisma dev stop. That is a design change, not a bug fix.Linked issue
n/a. Found by prisma/getting-started-eval#32 and recorded in that repository's README under "Findings to pass on".
Checklist
git commit -s) per the DCO.Agent: neptune-46
🤖 Generated with Claude Code