denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.66k stars 5.25k forks source link

App fails to start when running inside a Docker Container. #21748

Closed kyee-rs closed 9 months ago

kyee-rs commented 9 months ago

Version: Deno 1.39.1

Full error message:

Download ....

#
# Fatal error in , line 0
# Check failed: module->status() == kEvaluating || module->status() == kEvaluated.
#
#
#
#FailureMessage Object: 0x7ffdb77377b0
==== C stack trace ===============================

    /bin/deno(+0x28b11f3) [0x55b6f854f1f3]
    /bin/deno(+0x28b00bb) [0x55b6f854e0bb]
    /bin/deno(+0x28abc35) [0x55b6f8549c35]
    /bin/deno(+0x2db396b) [0x55b6f8a5196b]
    /bin/deno(+0x2db3528) [0x55b6f8a51528]
    /bin/deno(+0x294fc3b) [0x55b6f85edc3b]
    /bin/deno(+0x3a0aa36) [0x55b6f96a8a36]

Dockerfile:

# Based on https://github.com/denoland/deno_docker/blob/main/distroless.dockerfile

ARG DENO_VERSION=1.39.0
ARG BIN_IMAGE=denoland/deno:bin-${DENO_VERSION}
FROM ${BIN_IMAGE} AS bin

FROM gcr.io/distroless/cc

ENV DENO_DIR /deno-dir/
ENV DENO_INSTALL_ROOT /usr/local

ARG DENO_VERSION
ENV DENO_VERSION=${DENO_VERSION}
COPY --from=bin /deno /bin/deno

WORKDIR /deno-dir
COPY . .

ENTRYPOINT ["/bin/deno"]

I've also tried to build the image based on Debian, Ubuntu, Alpine. The error message does not change.

My starting command

$ docker run local:emphira run --allow-net --lock=deno.lock --lock-write ./runtime.ts

My runtime.ts

import { InlineKeyboard } from "https://deno.land/x/grammy@v1.19.2/mod.ts";
import { InputFile } from "https://deno.land/x/grammy@v1.19.2/types.deno.ts";
import { withAccelerate } from "https://esm.sh/@prisma/extension-accelerate@0.6.2";
import dayjs from "https://esm.sh/v132/dayjs@1.11.9";
import "https://esm.sh/v132/dayjs@1.11.9/locale/uk";
import { bot, i18n } from "./core/bot/mod.ts";
import { PrismaClient } from "./generated/client/deno/edge.ts";

export const prisma = new PrismaClient().$extends(withAccelerate());
await prisma.$connect();

Deno.cron("notify admins", "0 7 * * *", async () => {
    // UNRELATED TO THE ISSUE
});

Deno.cron("send absent students", "0 0 1 * *", async () => {
    // UNRELATED TO THE ISSUE
});

await bot.init();

await bot.api.deleteWebhook();

bot.start({
    drop_pending_updates: true,
});

bot.catch((err: Error) => {
    console.error(err);
});
console.log(`🦄 Initialized as @${bot.botInfo.username}`);
kyee-rs commented 9 months ago

I see that @piscisaureus commented that it is a V8-related bug and it should be fixed already but I am still able to reproduce it on the latest version and I don't know which module causes it.

kyee-rs commented 9 months ago

My best guess is that it has to do with the import of the prisma (--no-engine), but I don't have enough knowledge to prove or disprove it.

kt3k commented 9 months ago

Is your host os linux?

What happens if you run docker run local:emphira eval "console.log(1)"?

kyee-rs commented 9 months ago

Is your host os linux?

Kind of. My local instance's host OS is Windows but I also deploy to Fly.io, which I believe uses Linux under the hood. Also, the problem suddenly disappeared without any code changes, just rebuilt the app a couple of times and it is now working. The only change I made is that I added some environment variables BOT_TOKEN and DATABASE_URL, I don't really know if they were the reason of my app crashing.

kyee-rs commented 9 months ago

Both variables are being checked in the code like this...

const variable = Deno.env.get("BOT_TOKEN") // or DATABASE_URL
if (!variable) throw new Error("Environment is unfull")

So I don't really know why the app was crashing without Environment is unfull but with the error above.

kt3k commented 9 months ago

Thanks for reporting back. Closing this issue for now as it is resolved now. Please reopen when you see the same problem again