remix-run / blues-stack

The Remix Stack for deploying to Fly with PostgreSQL, authentication, testing, linting, formatting, etc.
https://remix.run/stacks
MIT License
961 stars 236 forks source link

Fly.io -> Error: Can't reach database server #182

Closed mathimariman closed 1 year ago

mathimariman commented 1 year ago

Have you experienced this bug with the latest version of the template?

yes

Steps to Reproduce

  1. Create app using: npx create-remix@latest --template remix-run/blues-stack
  2. Create application in fly.io using following commands: 2.1 Create app: fly apps create app-name-here 2.2 Set app secret variable: fly secrets set SESSION_SECRET=$(openssl rand -hex 32) --app app-name-here 2.3 Create database: fly postgres create --name db-name-here 2.4 Link database fly postgres attach --app app-name-here db-name-here
  3. Start Github workflow (push to main)

Expected Behavior

Application should be deployed

Actual Behavior

Error while deploying the application:

Error: Can't reach database server at ams.db-name-here.flycast:5432

mathimariman commented 1 year ago

It looks like the FLY_REGION variable is causing the issue. Error: Can't reach database server at ams.db-name-here.flycast:5432

Running the command fly postgres attach --app app-name-here db-name-here will create a database user and set the DATABASE_URL secret for the attached application. -> This secret (DATABASE_URL) doesn't contain the FLY_REGION part (ams in my case)

In file app/db.server.ts I see that the FLY_REGION is added to the DATABASE_URL when not running on localhost:

if (!isLocalHost) { databaseUrl.host = ${FLY_REGION}.${databaseUrl.host}; if (!isReadReplicaRegion) { // 5433 is the read-replica port databaseUrl.port = "5433"; } }

By removing the line which is adding the FLY_REGION (databaseUrl.host = ${FLY_REGION}.${databaseUrl.host};, the deployment is successful again.

I have been testing with other regions as well -> same error

kwigley commented 1 year ago

Following this to see why this occurred: https://community.fly.io/t/my-postgres-database-is-down-for-no-reason/12664

theobile commented 1 year ago

Following this to see why this occurred: https://community.fly.io/t/my-postgres-database-is-down-for-no-reason/12664

The link seems to be broken

iemesowum commented 1 year ago

It works if you're logged in.

alexpunct commented 1 year ago

Oh man, I spent the whole day trying to figure out what I was doing wrong... thanks for the solution!

mathimariman commented 1 year ago

Following this to see why this occurred: https://community.fly.io/t/my-postgres-database-is-down-for-no-reason/12664

Do you have an update on this one?

MoSattler commented 1 year ago

some issues are popping up again with connecting to fly DBs