Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

g1t.sh

Commit

A container app that ends before it answers says why when Cloudflare does: the reason its monitor gives is logged as g1t-container-ended and shown on the app's 503 page, where only an unknown exit code was.

syntaqxcommitted Parentd2e102bBrowse files
1 file+8−20/1 viewed
+8−2
306306 this.listening = false;
307307 // How it ended, if it ends: said on the page of a request it never answered.
308308 this.exited = null;
309+ this.why = null;
309310 if (typeof container.monitor === "function") {
310311 container.monitor().then(
311312 () => { this.exited = "0"; },
312− (error) => { this.exited = error && error.exitCode !== undefined ? String(error.exitCode) : "unknown"; },
313+ (error) => {
314+ this.exited = error && error.exitCode !== undefined ? String(error.exitCode) : "unknown";
315+ // Why it ended, when Cloudflare says: in the app's logs and on its page.
316+ this.why = error && error.message ? String(error.message).slice(0, 300) : null;
317+ console.error("g1t-container-ended", JSON.stringify({ exitCode: error?.exitCode ?? null, message: this.why }));
318+ },
313319 );
314320 }
315321 await this.tick();
317323 // A backstop: g1t stops it itself once it has slept long enough.
318324 await container.setInactivityTimeout((Number(env.G1T_SLEEP_MS) || 300000) + 2 * TICK_MS).catch(() => undefined);
319325 if (!(await this.ready(container, port))) {
320− const ended = this.exited === null || this.exited === undefined ? "It is not answering on port " + port + "." : "It stopped (exit code " + this.exited + ") before it answered on port " + port + ".";
326+ const ended = (this.exited === null || this.exited === undefined ? "It is not answering on port " + port + "." : "It stopped (exit code " + this.exited + ") before it answered on port " + port + ".") + (this.why ? " Cloudflare said: " + this.why : "");
321327 return page(503, "The app did not start", ended + " It must listen on 0.0.0.0 at the port in the PORT environment variable (the one its Dockerfile exposes, else 8080).");
322328 }
323329 let response;