feat: add db-pool-automatic-recovery configuration to disable connection retrying

This commit is contained in:
Taimoor Zaeem
2023-08-23 21:08:04 -05:00
committed by GitHub
parent b8b3145c5c
commit 57fa2719dd
17 changed files with 67 additions and 6 deletions
+1
View File
@@ -8,6 +8,7 @@ db-pool = 10
db-pool-acquisition-timeout = 10
db-pool-max-lifetime = 1800
db-pool-max-idletime = 5
db-pool-automatic-recovery = true
db-pre-request = "check_alias"
db-prepared-statements = true
db-root-spec = "open_alias"
@@ -8,6 +8,7 @@ db-pool = 10
db-pool-acquisition-timeout = 10
db-pool-max-lifetime = 1800
db-pool-max-idletime = 30
db-pool-automatic-recovery = true
db-pre-request = ""
db-prepared-statements = false
db-root-spec = ""
@@ -8,6 +8,7 @@ db-pool = 10
db-pool-acquisition-timeout = 10
db-pool-max-lifetime = 1800
db-pool-max-idletime = 30
db-pool-automatic-recovery = true
db-pre-request = ""
db-prepared-statements = false
db-root-spec = ""
+1
View File
@@ -8,6 +8,7 @@ db-pool = 10
db-pool-acquisition-timeout = 10
db-pool-max-lifetime = 1800
db-pool-max-idletime = 30
db-pool-automatic-recovery = true
db-pre-request = ""
db-prepared-statements = true
db-root-spec = ""
@@ -8,6 +8,7 @@ db-pool = 1
db-pool-acquisition-timeout = 30
db-pool-max-lifetime = 3600
db-pool-max-idletime = 60
db-pool-automatic-recovery = false
db-pre-request = "test.other_custom_headers"
db-prepared-statements = false
db-root-spec = "other_root"
@@ -8,6 +8,7 @@ db-pool = 1
db-pool-acquisition-timeout = 30
db-pool-max-lifetime = 3600
db-pool-max-idletime = 60
db-pool-automatic-recovery = false
db-pre-request = "test.custom_headers"
db-prepared-statements = false
db-root-spec = "root"
@@ -8,6 +8,7 @@ db-pool = 1
db-pool-acquisition-timeout = 30
db-pool-max-lifetime = 3600
db-pool-max-idletime = 60
db-pool-automatic-recovery = false
db-pre-request = "please_run_fast"
db-prepared-statements = false
db-root-spec = "openapi_v3"
+1
View File
@@ -8,6 +8,7 @@ db-pool = 10
db-pool-acquisition-timeout = 10
db-pool-max-lifetime = 1800
db-pool-max-idletime = 30
db-pool-automatic-recovery = true
db-pre-request = ""
db-prepared-statements = true
db-root-spec = ""
+1
View File
@@ -10,6 +10,7 @@ PGRST_DB_POOL: 1
PGRST_DB_POOL_ACQUISITION_TIMEOUT: 30
PGRST_DB_POOL_MAX_LIFETIME: 3600
PGRST_DB_POOL_MAX_IDLETIME: 60
PGRST_DB_POOL_AUTOMATIC_RECOVERY: false
PGRST_DB_PREPARED_STATEMENTS: false
PGRST_DB_PRE_REQUEST: please_run_fast
PGRST_DB_ROOT_SPEC: openapi_v3
+1
View File
@@ -8,6 +8,7 @@ db-pool = 1
db-pool-acquisition-timeout = 30
db-pool-max-lifetime = 3600
db-pool-max-idletime = 60
db-pool-automatic-recovery = false
db-pre-request = "please_run_fast"
db-prepared-statements = false
db-root-spec = "openapi_v3"
+5 -1
View File
@@ -173,4 +173,8 @@ select application_name
from pg_stat_activity
where application_name ilike 'postgrest%'
limit 1;
$$
$$;
create function terminate_pgrst() returns setof record as $$
select pg_terminate_backend(pid) from pg_stat_activity where application_name iLIKE '%postgrest%';
$$ language sql security definer;
+32
View File
@@ -1063,3 +1063,35 @@ def test_succeed_w_role_having_superuser_settings(defaultenv):
response = postgrest.session.get("/projects", headers=headers)
print(response.text)
assert response.status_code == 200
def test_fail_with_invalid_dbname_and_automatic_recovery_disabled(defaultenv):
"Should fail without retries when automatic recovery is disabled and dbname is invalid"
dbname = "INVALID"
uri = f'postgresql://?dbname={dbname}&host={defaultenv["PGHOST"]}&user={defaultenv["PGUSER"]}'
env = {
**defaultenv,
"PGRST_DB_URI": uri,
"PGRST_DB_POOL_AUTOMATIC_RECOVERY": "false",
}
with run(env=env, wait_for_readiness=False) as postgrest:
exitCode = wait_until_exit(postgrest)
assert exitCode == 1
def test_fail_with_automatic_recovery_disabled_and_terminated_using_query(defaultenv):
"Should fail without retries when automatic recovery is disabled and pg_terminate_backend(pid) is called"
env = {
**defaultenv,
"PGRST_DB_POOL_AUTOMATIC_RECOVERY": "false",
}
with run(env=env) as postgrest:
os.system(
f'psql -d {defaultenv["PGDATABASE"]} -U {defaultenv["PGUSER"]} -h {defaultenv["PGHOST"]} --set ON_ERROR_STOP=1 -a -c "SELECT terminate_pgrst()"'
)
exitCode = wait_until_exit(postgrest)
assert exitCode == 1
+1
View File
@@ -91,6 +91,7 @@ baseCfg = let secret = Just $ encodeUtf8 "reallyreallyreallyreallyverysafe" in
, configDbPoolAcquisitionTimeout = 10
, configDbPoolMaxLifetime = 1800
, configDbPoolMaxIdletime = 600
, configDbPoolAutomaticRecovery = True
, configDbPreRequest = Just $ QualifiedIdentifier "test" "switch_role"
, configDbPreparedStatements = True
, configDbRootSpec = Nothing