Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/PostgREST/AppState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,6 @@ retryingSchemaCacheLoad appState@AppState{stateObserver=observer, stateMainThrea
let delay = fromMaybe 0 rsPreviousDelay `div` oneSecondInUs
observer $ ConnectionRetryObs delay

flushPool appState

(,) <$> qPgVersion <*> (qInDbConfig *> qSchemaCache)
)
where
Expand Down Expand Up @@ -365,6 +363,10 @@ retryingSchemaCacheLoad appState@AppState{stateObserver=observer, stateMainThrea
-- IORef on putSchemaCache. This is why schema cache status is marked as pending here to signal the Admin server (using isPending) that we're on a recovery state.
markSchemaCachePending appState
putSchemaCache appState $ Just sCache
-- Flush the pool after loading the schema cache to reset any stale session cache entries
-- We do it after successfully querying the schema cache
-- and after marking sCacheStatus as pending,
flushPool appState
observer $ SchemaCacheQueriedObs resultTime
observer . uncurry SchemaCacheLoadedObs =<< timeItT (evaluate $ showSummary sCache)
markSchemaCacheLoaded appState
Expand Down
8 changes: 4 additions & 4 deletions test/io/test_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ def test_log_level(level, defaultenv):
response = postgrest.session.get("/")
assert response.status_code == 200

output = postgrest.read_stdout(nlines=7)
output = postgrest.read_stdout(nlines=9)

if level == "crit":
assert len(output) == 0
Expand Down Expand Up @@ -819,7 +819,7 @@ def test_log_level(level, defaultenv):
r'- - postgrest_test_anonymous \[.+\] "GET / HTTP/1.1" 200 \d+ "" "python-requests/.+"',
],
)
assert len(output) == 7
assert len(output) == 9
assert any("Connection" and "is available" in line for line in output)
assert any("Connection" and "is used" in line for line in output)

Expand Down Expand Up @@ -1456,7 +1456,7 @@ def test_db_error_logging_to_stderr(level, defaultenv, metapostgrest):
assert response.status_code == 500

# ensure the message appears on the logs
output = postgrest.read_stdout(nlines=6)
output = postgrest.read_stdout(nlines=8)

if level == "crit":
assert len(output) == 0
Expand Down Expand Up @@ -1673,7 +1673,7 @@ def test_log_pool_req_observation(level, defaultenv):

if level == "debug":
output = postgrest.read_stdout(nlines=7)
assert len(output) == 6
assert len(output) == 7
match_log(output, [pool_req, pool_req_fullfill])
elif level == "info":
output = postgrest.read_stdout(nlines=4)
Expand Down
6 changes: 2 additions & 4 deletions test/observability/Observation/SchemaCacheSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ spec = describe "Server started with metrics enabled" $ do
waitFor (1 * sec) "SchemaCacheLoadedObs" $ \x -> [ o | o@SchemaCacheLoadedObs{} <- pure x ]


it "Should flush pool multiple times when schema reloading retries" $ do
it "Should flush pool once when schema reloading retries" $ do
SpecState{specAppState = appState, specObsChan} <- getState
let waitFor = waitForObs specObsChan

Expand All @@ -36,16 +36,14 @@ spec = describe "Server started with metrics enabled" $ do
AppState.putConfig appState $ cfg { configDbSchemas = pure "bad_schema" }
AppState.schemaCacheLoader appState

waitFor (1 * sec) "PoolFlushed 1" $ \x -> [ o | o@PoolFlushed <- pure x ]
waitFor (1 * sec) "SchemaCacheErrorObs" $ \x -> [ o | o@SchemaCacheErrorObs{} <- pure x ]

-- Restore configuration
AppState.putConfig appState cfg

-- Wait for 2 seconds so that retry can happen
waitFor (2 * sec) "PoolFlushed 2" $ \x -> [ o | o@PoolFlushed <- pure x ]
waitFor (2 * sec) "PoolFlushed" $ \x -> [ o | o@PoolFlushed <- pure x ]
waitFor (1 * sec) "SchemaCacheQueriedObs" $ \x -> [ o | o@SchemaCacheQueriedObs{} <- pure x ]
waitFor (1 * sec) "SchemaCacheLoadedObs" $ \x -> [ o | o@SchemaCacheLoadedObs{} <- pure x ]

where
sec = 1000000