supabase / cli

Supabase CLI. Manage postgres migrations, run Supabase locally, deploy edge functions. Postgres backups. Generating types from your database schema.
https://supabase.com/docs/reference/cli/about
MIT License
930 stars 179 forks source link

PostgREST 12.1 frequently stuck in "Attempting to connect to the database..." (Local Development) #2361

Open vhpx opened 2 weeks ago

vhpx commented 2 weeks ago

Describe the bug

Supabase PostgREST docker container logs:

2024-06-03 16:12:18 03/Jun/2024:09:12:18 +0000: Starting PostgREST 12.1...
2024-06-03 16:12:18 03/Jun/2024:09:12:18 +0000: Attempting to connect to the database...
2024-06-03 16:12:18 03/Jun/2024:09:12:18 +0000: Admin server listening on port 3001
2024-06-03 16:12:18 03/Jun/2024:09:12:18 +0000: Listening on port 3000
2024-06-03 16:12:18 03/Jun/2024:09:12:18 +0000: Listening for notifications on the "pgrst" channel
2024-06-03 16:12:18 03/Jun/2024:09:12:18 +0000: Successfully connected to PostgreSQL 15.1 (Ubuntu 15.1-1.pgdg20.04+1) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0, 64-bit
2024-06-03 16:12:18 03/Jun/2024:09:12:18 +0000: Config reloaded
2024-06-03 16:12:19 03/Jun/2024:09:12:18 +0000: Schema cache queried in 7.2 milliseconds
2024-06-03 16:12:19 03/Jun/2024:09:12:18 +0000: Schema cache loaded 87 Relations, 83 Relationships, 48 Functions, 0 Domain Representations, 4 Media Type Handlers
2024-06-03 16:17:57 03/Jun/2024:09:17:57 +0000: Starting PostgREST 12.1...
2024-06-03 16:17:57 03/Jun/2024:09:17:57 +0000: Attempting to connect to the database...
2024-06-03 16:17:57 03/Jun/2024:09:17:57 +0000: Admin server listening on port 3001
2024-06-03 16:17:57 03/Jun/2024:09:17:57 +0000: Listening on port 3000
2024-06-03 16:17:57 Assertion failed: *(&once->n) != 4 (threads.c: k5_once: 564)
2024-06-03 16:17:57 03/Jun/2024:09:17:57 +0000: Starting PostgREST 12.1...
2024-06-03 16:17:57 03/Jun/2024:09:17:57 +0000: Attempting to connect to the database...
2024-06-03 16:17:57 03/Jun/2024:09:17:57 +0000: Admin server listening on port 3001
2024-06-03 16:17:57 03/Jun/2024:09:17:57 +0000: Listening on port 3000
2024-06-03 16:17:57 Assertion failed: *(&once->n) != 4 (threads.c: k5_once: 564)
2024-06-03 16:17:58 03/Jun/2024:09:17:58 +0000: Starting PostgREST 12.1...
2024-06-03 16:17:58 03/Jun/2024:09:17:58 +0000: Attempting to connect to the database...
2024-06-03 16:17:58 03/Jun/2024:09:17:58 +0000: Admin server listening on port 3001
2024-06-03 16:17:58 03/Jun/2024:09:17:58 +0000: Listening on port 3000
2024-06-03 16:17:58 Assertion failed: *(&once->n) != 4 (threads.c: k5_once: 564)
2024-06-03 16:17:59 03/Jun/2024:09:17:59 +0000: Starting PostgREST 12.1...
2024-06-03 16:17:59 03/Jun/2024:09:17:59 +0000: Attempting to connect to the database...
2024-06-03 16:17:59 03/Jun/2024:09:17:59 +0000: Admin server listening on port 3001
2024-06-03 16:17:59 03/Jun/2024:09:17:59 +0000: Listening on port 3000
2024-06-03 16:17:59 Assertion failed: *(&once->n) != 4 (threads.c: k5_once: 564)
2024-06-03 16:18:01 03/Jun/2024:09:18:01 +0000: Starting PostgREST 12.1...
2024-06-03 16:18:01 03/Jun/2024:09:18:01 +0000: Attempting to connect to the database...
2024-06-03 16:18:01 03/Jun/2024:09:18:01 +0000: Admin server listening on port 3001
2024-06-03 16:18:01 03/Jun/2024:09:18:01 +0000: Listening on port 3000
2024-06-03 16:18:01 Assertion failed: *(&once->n) != 4 (threads.c: k5_once: 564)
2024-06-03 16:18:05 03/Jun/2024:09:18:05 +0000: Starting PostgREST 12.1...
2024-06-03 16:18:05 03/Jun/2024:09:18:05 +0000: Attempting to connect to the database...
2024-06-03 16:18:05 03/Jun/2024:09:18:05 +0000: Admin server listening on port 3001
2024-06-03 16:18:05 03/Jun/2024:09:18:05 +0000: Listening on port 3000
2024-06-03 16:18:05 Assertion failed: *(&once->n) != 4 (threads.c: k5_once: 564)
2024-06-03 16:18:12 03/Jun/2024:09:18:12 +0000: Starting PostgREST 12.1...
2024-06-03 16:18:12 03/Jun/2024:09:18:12 +0000: Attempting to connect to the database...
2024-06-03 16:18:12 03/Jun/2024:09:18:12 +0000: Admin server listening on port 3001
2024-06-03 16:18:12 03/Jun/2024:09:18:12 +0000: Listening on port 3000
2024-06-03 16:18:12 Assertion failed: *(&once->n) != 4 (threads.c: k5_once: 564)

Which makes Next.js unable to produce development output when developing using pnpm dev, and returns the following error in the console:

{
  code: 'PGRST002',
  details: null,
  hint: null,
  message: 'Could not query the database for the schema cache. Retrying.',
  digest: '4171135552'
}

and the error that prevented the development build output:

{
  message: 'An invalid response was received from the upstream server',
  digest: '1306904865'
}

System information

vhpx commented 2 weeks ago

image

It keeps restarting on its own, I'm significantly slowed down in development due to this bug.

vhpx commented 2 weeks ago

Update: reverted PostgREST to v12.0.2 and monitored for about 30 minutes, seems like the bug has been resolved on the earlier version. I think PostgREST v12.1 isn't stable to be used yet for my development flow.

sweatybridge commented 2 weeks ago

Thanks for reporting this. I will ping PostgREST team to check if there's a fix.

sweatybridge commented 2 weeks ago

Does the error happen on your hosted project or just local?

vhpx commented 2 weeks ago

Looks like staging is unaffected, so I'm assuming it only happens on local for now. I'll closely monitor my hosted instance if it happens there.

steve-chavez commented 2 weeks ago
postgrest/postgrest    │ v12.1                │ v12.1

Hm, PostgREST hasn't yet released v12.1, check https://hub.docker.com/r/postgrest/postgrest/tags. Latest release is v12.0.3.

@sweatybridge Could you clarify from where is the v12.1 coming?

Tried grepping for the code but I got this which says v12.0.1 https://github.com/supabase/cli/blob/c5febaf8c6dbcaeda44e85a12a66715bfc4809fd/internal/utils/misc.go#L33

sweatybridge commented 2 weeks ago

v12.1 is an alias for devel tag that's published only in supabase ECR and GHCR. Docker hub doesn't have v12.1, only devel.

steve-chavez commented 2 weeks ago

Hm, this should be corrected then:

 postgrest/postgrest    │ v12.1                │ v12.1

It's misleading since it doesn't come from postgREST upstream.

v12.1 is an alias for devel tag that's published only in supabase ECR and GHCR

@sweatybridge How can I introspect those dockerfiles?


2024-06-03 16:17:58 Assertion failed: *(&once->n) != 4 (threads.c: k5_once: 564)

This error is coming from kerberos(ref), which is a C library. It could be an issue with how the image is built.

sweatybridge commented 2 weeks ago

Since user is having problem on windows and not hosted, this error might be only specific to amd64 image of PostgREST. The v12.1 tag is available here https://github.com/supabase/cli/pkgs/container/postgrest/223414607?tag=v12.1

May be you can inspect it after docker pull ghcr.io/supabase/postgrest:v12.1

vhpx commented 2 weeks ago

Probably related: https://github.com/PostgREST/postgrest/issues/3569

guigzp commented 5 days ago

Any fixes for this? I cant start my local environment with this error

vhpx commented 5 days ago

@guigzp for now, change the value in supabase/.temp/rest_version to v12.0.2 and restart local cli, it should work as a temporary fix.

steve-chavez commented 5 days ago

This is already fixed upstream. It should be solved here after https://github.com/supabase/postgres/pull/1003 is merged.

guigzp commented 5 days ago

Changing supabase/.temp/rest_version to v12.0.2 solved but I had to use version 1.150.0 of the CLI as the latest was not working for me.