Guard against too many pool waiters

As I think this is happening when there are an excessive number of requests,
and that in turn causes issues with file descriptor limits.
This commit is contained in:
Christopher Baines 2025-04-27 11:40:44 +01:00
parent cde34344f8
commit ca80a051ff

View file

@ -203,6 +203,9 @@ port. Also, the port used can be changed by passing the --port option.\n"
#:destructor #:destructor
(lambda (conn) (lambda (conn)
(close-postgresql-connection conn "web")) (close-postgresql-connection conn "web"))
#:default-max-waiters 300
#:default-checkout-timeout (/ postgresql-statement-timeout
1000)
#:scheduler priority-scheduler)) #:scheduler priority-scheduler))
(reserved-connection-pool (reserved-connection-pool
@ -263,7 +266,10 @@ port. Also, the port used can be changed by passing the --port option.\n"
(let ((path-components (let ((path-components
mime-types mime-types
(request->path-components-and-mime-type request))) (request->path-components-and-mime-type request))
(pool-exn?
(or (resource-pool-timeout-error? exn)
(resource-pool-too-many-waiters-error? exn))))
(case (most-appropriate-mime-type (case (most-appropriate-mime-type
mime-types mime-types
'(text/html application/json)) '(text/html application/json))
@ -273,7 +279,9 @@ port. Also, the port used can be changed by passing the --port option.\n"
(render-json `((error . ,(if (%show-error-details) (render-json `((error . ,(if (%show-error-details)
(simple-format #f "~A" exn) (simple-format #f "~A" exn)
#f))) #f)))
#:code 500))) #:code (if pool-exn?
503
500))))
(else (else
(apply (apply
values values
@ -281,7 +289,9 @@ port. Also, the port used can be changed by passing the --port option.\n"
(if (%show-error-details) (if (%show-error-details)
exn exn
#f)) #f))
#:code 500)))))) #:code (if pool-exn?
503
500)))))))
(lambda () (lambda ()
(with-exception-handler (with-exception-handler
(lambda (exn) (lambda (exn)