can't fetch external urls from node (timeout error)

I can’t figure out how to fetch external urls from my node app.
I’m really stuck, thank you for any help.

I have boiled it down to this very simple example (which works locally from my machine):

const run = async () => {

	const res1 = await (await fetch('')).text()
	console.log({ res1 })




(node:613) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
    Error.captureStackTrace(err, this);

TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11118:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async run (file:///app/flydebug.js:3:22) {
  cause: ConnectTimeoutError: Connect Timeout Error
      at onConnectTimeout (node:internal/deps/undici/undici:6625:28)
      at node:internal/deps/undici/undici:6583:50
      at Immediate._onImmediate (node:internal/deps/undici/undici:6614:13)
      at process.processImmediate (node:internal/timers:471:21) {

This, however, works

From fly ssh console


Some bits from fly ssh console > printenv



app = "di"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

  source = "data"
  destination = "/app/data"

  allowed_public_ports = []
  auto_rollback = true

  http_checks = []
  internal_port = 3000
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
    hard_limit = 25
    soft_limit = 20
    type = "connections"

    force_https = true
    handlers = ["http"]
    port = 80

    handlers = ["tls", "http"]
    port = 443

    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"


FROM node:18-alpine


COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

COPY . .
RUN yarn vite build

RUN apk add --no-cache curl

CMD [ "yarn", "start" ]


Yep, I’ve had that before when running Node on Alpine. Check out this thread:

Essentially the “fix” is not using Alpine as the base image. That resolved the issue for both me and this other guy anyway :slight_smile:.

I saw your thread before, but forgot to mention it.
I tried your suggestion and various other distributions without success.
But thank you for your help anyway, I appreciate it!! :slight_smile:

I just found a solution to my problem though:

I destroyed the app on and re-deployed it as-is on a new instance, problem gone.

Everything else stayed the same, apart from adding these to my Dockerfile (new lines prefixed with a +):

FROM node:18-alpine

+ LABEL fly_launch_runtime="nodejs"


COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile

COPY . .
RUN yarn prisma migrate deploy
RUN yarn prisma generate
RUN yarn vite build

+ ENV NODE_ENV production

CMD [ "yarn", "start" ]

The only other difference I can think of, is that the previous instance was initially using a buildpack, then was changed to use a Dockerfile. Maybe that affected the instance in some permanent way.

In any case, what I did was basically to “to turn it off and on again”. It worked, I just wish I had thought of that earlier.

1 Like