App starting but not available somehow

Hello lovely people of the fly.io community!

I’ve been giving fly a try today but haven’t been able to get my app up and running and I’m out of knowledge what I’m doing wrong.

My fly.toml currently looks like this here:

# fly.toml file generated for website-api on 2022-07-13T18:31:36+02:00

app = "website-api"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[env]
  PORT=8080

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 8080
  processes = ["app"]
  protocol = "tcp"
  script_checks = []
  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    force_https = true
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"

My app is running on port 8080 and the health checks report back as green, but the app itself is not reachable.

The logs in monitoring show this here:

Does anyone have a clue on what I’m doing wrong?

I’m looking forward to your posts.

Thank you very much and have a joyful day!

Best wishes
Tom

Hey there!

So based on the log output, it looks like a Nodejs web app.

Can you show us what networks the app is set to listen on?

For example, an Express app should listen on all networks, which is done by specifying just a port: app.listen(8080)

1 Like

Hey Chris,

thanks for your reply.

Yes, you’re right, it’s a nodejs app (feels like cheating on PHP and Laravel, I know). It’s a non modified version of payloadCMS.

My server.js looks currently like this:

const express = require('express');
const payload = require('payload');

require('dotenv').config();
const app = express();

// Redirect root to Admin panel
app.get('/', (_, res) => {
  res.redirect('/admin');
});

// Initialize Payload
payload.init({
  secret: process.env.PAYLOAD_SECRET,
  mongoURL: process.env.MONGODB_URI,
  express: app,
  onInit: () => {
    payload.logger.info(`Payload Admin URL: ${payload.getAdminURL()}`);
  },
});

// Add your own express routes here

app.listen(process.env.PORT || 3000);

Also this is my Dockerfile:

# https://docs.docker.com/samples/library/node/
ARG NODE_VERSION=16

# Build container
FROM node:${NODE_VERSION}-alpine AS build
ARG DUMB_INIT_VERSION

WORKDIR /home/node

ADD . /home/node

RUN apk add git

RUN yarn install

RUN yarn build && yarn cache clean

# Runtime container
FROM node:${NODE_VERSION}-alpine

WORKDIR /home/node

COPY --from=build /home/node /home/node

EXPOSE 8080
CMD ["yarn", "run", "serve"]

I believe .env won’t over-ride a system environment variable, but I do wonder what your .env file has (if anything!)

One other way to help debug this is to SSH into it:

fly console ssh

> apk update && apk add curl vim
> curl localhost:8080/admin

You can poke around in there to see what’s happening.

I, unfortunately, wasn’t able to reproduce an issue making my own express app (minus PayloadCMS).

This combination of “stuff” all worked for me - very similar to what you have I believe (again, minus PayloadCMS - perhaps that’s related). Here’s a gist: Dockerfile · GitHub

1 Like

My .env file is empty, I’ve added 2 secrets for secret key and mongodb connection url and put the PORT env variable into the fly.toml file (as seen above).

The SSH command won’t connect:

▶ flyctl ssh console
Connecting to top1.nearest.of.website-api.internal... complete
Error error connecting to SSH server: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

This caused the following error in the monitoring error log:

2022-07-13T18:20:55.193 app[4ba72819] fra [info] 2022/07/13 18:20:55 unexpected error: transient SSH server error: can't resolve _orgcert.internal

2022-07-13T18:20:55.255 app[4ba72819] fra [info] 2022/07/13 18:20:55 unexpected error: [ssh: no auth passed yet, transient SSH server error: can't resolve _orgcert.internal]

Creating an organization certificate resulted in this message in my local console window:

▶ flyctl ssh establish
? Select organization: <snip> (<snip>)
Establishing SSH CA cert for organization <snip>
Error establish key failed: key exists and override not set

I’ll see what else I can do eg. remove everything and restart from scratch.

Thanks for helping me, Chris!

Best wishes
Tom


PROGRESS EDIT 1:
I’ve removed the app completely and was able to SSH into it afterwards.
The webserver is running on port 8080. It is reachable using curl -v http://0.0.0.0:8080/admin inside the application.
The .fly.io subdomain though is not reachable and isn’t announced with an IP address at all (dig can’t find it, same as pry.sh). The IP address of the application also doesn’t have any open ports somehow, neither 80 nor 443 work.


PROGRESS EDIT 2:
I didn’t do anything since my last edit but somehow the subdomain works now and I can reach my app. Strange, but awesome. Thanks to to whoever did this.

Summary:

  • I didn’t see that the subdomain of my app was not a subdomain of fly.io but instead of fly.dev.
  • Somehow it was reachable after another deployment and after using flyctl open.
  • SSH access also worked after completely removing the app and launching+deploying it again.

Everything seems to be normal and working now. I’ll keep this thread here updated on my progress :slight_smile:

Thanks for reading and have a great day.

1 Like

Great, thanks for letting us know!

One idea we were about to send was to deploy with an empty [[services]] block (meaning, just [[services]], no other lines) - that would remove health checks and likely allow you to ssh in.

However it sounds like a good old fashion “reboot” worked :thinking:

1 Like