| 306 | 306 | | this.listening = false; |
| 307 | 307 | | // How it ended, if it ends: said on the page of a request it never answered. |
| 308 | 308 | | this.exited = null; |
| 309 | + | this.why = null; |
| 309 | 310 | | if (typeof container.monitor === "function") { |
| 310 | 311 | | container.monitor().then( |
| 311 | 312 | | () => { 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 | + | }, |
| 313 | 319 | | ); |
| 314 | 320 | | } |
| 315 | 321 | | await this.tick(); |
| ⋯ |
| 317 | 323 | | // A backstop: g1t stops it itself once it has slept long enough. |
| 318 | 324 | | await container.setInactivityTimeout((Number(env.G1T_SLEEP_MS) || 300000) + 2 * TICK_MS).catch(() => undefined); |
| 319 | 325 | | 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 : ""); |
| 321 | 327 | | 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)."); |
| 322 | 328 | | } |
| 323 | 329 | | let response; |