Skip to content

Conversation

@laurenceisla
Copy link
Member

Closes #4129 as mentioned in the revision #4129 (comment).

@laurenceisla laurenceisla changed the title Fix 503 errors not logging the JSON messages and reloading the schema unnecessarily on startup Fix PGRST002 errors not logging the JSON messages and reloading the schema unnecessarily on startup Oct 8, 2025
@laurenceisla laurenceisla marked this pull request as ready for review October 8, 2025 06:20
hint (SchemaCacheErr err) = hint err
hint (JwtErr err) = hint err
hint NoSchemaCacheError = Nothing
hint NoSchemaCacheError = Just "This usually happens when PostgREST is starting up. Try again later."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we get the requests to wait like what happens after the schema cache is loaded? This would be the ideal behavior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laurenceisla Maybe if we drop the maybe from:

, stateSchemaCache :: IORef (Maybe SchemaCache)

The waiting will automatically happen

Copy link
Member Author

@laurenceisla laurenceisla Oct 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if we drop the maybe

Tried it out and did not work. There is no Nothing schema cache if this is the case, we have to use one with empty values (e.g. empty tables, empty functions, etc.). It doesn't wait automatically, it returns an immediate 404 response with this initial schema instead of a 503 with the PGRST002 error.

Can we get the requests to wait like what happens after the schema cache is loaded? This would be the ideal behavior.

I also think this would be ideal, it would also stop flooding the logs with PGRST002 errors for apps with a lot of requests. However this would be a different behavior from what we currently do when we restart the schema and respond before the schema is loaded. For example:

-- On startup:

Config reload
-- Requests are immediately rejected here with `PGRST002` errors
Schema queried
-- Requests wait until schema is loaded
Schema loaded

-- On a Schema Cache Reload:

Config reload
-- Requests are immediately handled using the stale schema
Schema queried
-- Requests wait until schema is loaded
Schema Loaded

So instead of immediately reject the request with PGRST002 we would wait instead. I'll check further on how to do that.

Copy link
Member

@steve-chavez steve-chavez Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Maybe this is too complicated right now. As it is, the PR is an improvement though as it surfaces an error.

The only problem is that the message looks a bit sloppy 🤔. I can't think of a better choice, maybe leave it as before or add a TODO comment.

Suggested change
hint NoSchemaCacheError = Just "This usually happens when PostgREST is starting up. Try again later."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Maybe this is too complicated right now.

Yeah, can confirm that it's not so trivial.

The only problem is that the message looks a bit sloppy 🤔. I can't think of a better choice, maybe leave it as before or add a TODO comment.

Yes, wasn't too convinced either. I'll remove it.

@laurenceisla laurenceisla force-pushed the fix/startup-503-errs branch 2 times, most recently from 39886b2 to a2bb823 Compare October 15, 2025 01:35
It happens right after the configuration is loaded and before
the schema cache is queried.
When 503 errors happen if the Schema Cache is empty,
it should not retrigger the connection worker since
there's no Schema Cache loaded yet.
@laurenceisla laurenceisla merged commit ea5db2a into PostgREST:main Oct 20, 2025
33 checks passed
@laurenceisla laurenceisla deleted the fix/startup-503-errs branch October 20, 2025 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Requests are rejected immediately when loading the Schema Cache on startup

2 participants