Skip to content
Open
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: 11 additions & 1 deletion runtime/middlewares/liveness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,22 @@ const buildHandler = (
}
});
};
// In production (k8s), SIGTERM comes from the kubelet and the process must
// shut down. In local dev, Deno's HMR/watch sends SIGTERM to the child
// process expecting a clean restart cycle — calling self.close() here kills
// the process before HMR can relaunch it, breaking hot-reload entirely.
// Deno runtime flags (--unstable-hmr, --watch) are NOT visible in Deno.args,
// so we detect production by the presence of KUBERNETES_SERVICE_HOST which is
// always injected into k8s pods.
const isK8s = Boolean(Deno.env.get("KUBERNETES_SERVICE_HOST"));
try {
if (Deno.build.os !== "windows") {
Deno.addSignalListener("SIGTERM", () => {
const checks = runChecks();
console.log(checks);
self.close();
if (isK8s) {
self.close();
Comment on lines +75 to +82

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Don't use Kubernetes presence as the shutdown default.

Lines 75-82 now change SIGTERM behavior from “close unless we're in watch/HMR” to “close only in Kubernetes”. That widens the behavior change to every non-k8s runtime, so ordinary production deployments outside Kubernetes will now skip self.close() too. The exception should be keyed off the specific dev/watch mode, with self.close() remaining the default for normal SIGTERM handling.

Suggested change
-  const isK8s = Boolean(Deno.env.get("KUBERNETES_SERVICE_HOST"));
+  const isWatchMode = Deno.env.get("DECO_WATCH_MODE") === "1";
   try {
     if (Deno.build.os !== "windows") {
       Deno.addSignalListener("SIGTERM", () => {
         const checks = runChecks();
         console.log(checks);
-        if (isK8s) {
+        if (!isWatchMode) {
           self.close();
         }
       });
     }
   } catch (err) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const isK8s = Boolean(Deno.env.get("KUBERNETES_SERVICE_HOST"));
try {
if (Deno.build.os !== "windows") {
Deno.addSignalListener("SIGTERM", () => {
const checks = runChecks();
console.log(checks);
self.close();
if (isK8s) {
self.close();
const isWatchMode = Deno.env.get("DECO_WATCH_MODE") === "1";
try {
if (Deno.build.os !== "windows") {
Deno.addSignalListener("SIGTERM", () => {
const checks = runChecks();
console.log(checks);
if (!isWatchMode) {
self.close();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@runtime/middlewares/liveness.ts` around lines 75 - 82, The SIGTERM handler in
liveness.ts now gates self.close() on Kubernetes detection, which makes non-K8s
production skips the default shutdown path. Update the logic in the SIGTERM
listener so the exception is based on the specific dev/watch/HMR mode instead of
isK8s, and keep self.close() as the default behavior for normal shutdown
handling in runChecks()/Deno.addSignalListener.

}
});
}
} catch (err) {
Expand Down
Loading