feat: introduce pool acquisition timeout (fixes #2348)

The configuration option db-pool-acquisition-timeout
specifies the time in seconds to wait for the pool to
free up a connection slot. Otherwise, a 504 error is
returned. By default, there is no timeout.
This commit is contained in:
Robert Vollmert
2022-08-31 19:54:34 +02:00
committed by Robert
parent 554db21f49
commit ba1fcfd1e3
16 changed files with 72 additions and 35 deletions
+1
View File
@@ -5,6 +5,7 @@ db-extra-search-path = "public"
db-max-rows = 1000
db-plan-enabled = false
db-pool = 10
db-pool-acquisition-timeout = ""
db-pre-request = "check_alias"
db-prepared-statements = true
db-root-spec = "open_alias"
@@ -5,6 +5,7 @@ db-extra-search-path = "public"
db-max-rows = ""
db-plan-enabled = false
db-pool = 10
db-pool-acquisition-timeout = ""
db-pre-request = ""
db-prepared-statements = false
db-root-spec = ""
@@ -5,6 +5,7 @@ db-extra-search-path = "public"
db-max-rows = ""
db-plan-enabled = false
db-pool = 10
db-pool-acquisition-timeout = ""
db-pre-request = ""
db-prepared-statements = false
db-root-spec = ""
+1
View File
@@ -5,6 +5,7 @@ db-extra-search-path = "public"
db-max-rows = ""
db-plan-enabled = false
db-pool = 10
db-pool-acquisition-timeout = ""
db-pre-request = ""
db-prepared-statements = true
db-root-spec = ""
@@ -5,6 +5,7 @@ db-extra-search-path = "public,extensions,other"
db-max-rows = 100
db-plan-enabled = true
db-pool = 1
db-pool-acquisition-timeout = 10
db-pre-request = "test.other_custom_headers"
db-prepared-statements = false
db-root-spec = "other_root"
@@ -5,6 +5,7 @@ db-extra-search-path = "public,extensions,private"
db-max-rows = 1000
db-plan-enabled = true
db-pool = 1
db-pool-acquisition-timeout = 10
db-pre-request = "test.custom_headers"
db-prepared-statements = false
db-root-spec = "root"
@@ -5,6 +5,7 @@ db-extra-search-path = "public,test"
db-max-rows = 1000
db-plan-enabled = true
db-pool = 1
db-pool-acquisition-timeout = 10
db-pre-request = "please_run_fast"
db-prepared-statements = false
db-root-spec = "openapi_v3"
+1
View File
@@ -5,6 +5,7 @@ db-extra-search-path = "public"
db-max-rows = ""
db-plan-enabled = false
db-pool = 10
db-pool-acquisition-timeout = ""
db-pre-request = ""
db-prepared-statements = true
db-root-spec = ""
+1
View File
@@ -7,6 +7,7 @@ PGRST_DB_EXTRA_SEARCH_PATH: public, test
PGRST_DB_MAX_ROWS: 1000
PGRST_DB_PLAN_ENABLED: true
PGRST_DB_POOL: 1
PGRST_DB_POOL_ACQUISITION_TIMEOUT: 10
PGRST_DB_PREPARED_STATEMENTS: false
PGRST_DB_PRE_REQUEST: please_run_fast
PGRST_DB_ROOT_SPEC: openapi_v3
+1
View File
@@ -5,6 +5,7 @@ db-extra-search-path = "public, test"
db-max-rows = 1000
db-plan-enabled = true
db-pool = 1
db-pool-acquisition-timeout = 10
db-pre-request = "please_run_fast"
db-prepared-statements = false
db-root-spec = "openapi_v3"
+16
View File
@@ -548,6 +548,22 @@ def test_pool_size(defaultenv, metapostgrest):
assert delta > 1 and delta < 1.5
def test_pool_acquisition_timeout(defaultenv, metapostgrest):
"Verify that PGRST_DB_POOL_ACQUISITON_TIMEOUT times out when the pool is empty"
env = {
**defaultenv,
"PGRST_DB_POOL": "1",
"PGRST_DB_POOL_ACQUISITION_TIMEOUT": "1", # 1 second
}
with run(env=env, no_pool_connection_available=True) as postgrest:
response = postgrest.session.get("/projects")
assert response.status_code == 504
data = response.json()
assert data["message"] == "Timed out acquiring connection from connection pool."
def test_change_statement_timeout_held_connection(defaultenv, metapostgrest):
"Statement timeout changes take effect immediately, even with a request outliving the reconfiguration"
+1
View File
@@ -79,6 +79,7 @@ baseCfg = let secret = Just $ encodeUtf8 "reallyreallyreallyreallyverysafe" in
, configDbMaxRows = Nothing
, configDbPlanEnabled = False
, configDbPoolSize = 10
, configDbPoolAcquisitionTimeout = Nothing
, configDbPreRequest = Just $ QualifiedIdentifier "test" "switch_role"
, configDbPreparedStatements = True
, configDbRootSpec = Nothing