Skip to content

Commit 2ffd873

Browse files
authored
Merge pull request #1148 from terrateamio/1147-fix-lock-timeout
#1147 FIX Default lock and statement timeouts
2 parents f4639c9 + c90008c commit 2ffd873

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

code/src/terrat_storage/terrat_storage.ml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
let src = Logs.Src.create "storage"
22

33
module Logs = (val Logs.src_log src : Logs.LOG)
4+
module Fc = Abbs_future_combinators
45

56
module Queue_time_histogram = Prmths.Histogram (struct
67
let spec = Prmths.Histogram_spec.of_list [ 0.01; 0.1; 0.25; 0.5; 1.0; 2.5; 5.0; 7.5; 10.0; 15.0 ]
@@ -33,11 +34,21 @@ let metrics Pgsql_pool.Metrics.{ num_conns; idle_conns; queue_time } =
3334

3435
let on_connect idle_tx_timeout conn =
3536
Abbs_future_combinators.ignore
36-
(let open Abb.Future.Infix_monad in
37-
Pgsql_io.Prepared_stmt.execute
38-
conn
39-
Pgsql_io.Typed_sql.(
40-
sql /^ Printf.sprintf "set idle_in_transaction_session_timeout='%s'" idle_tx_timeout)
37+
(let go () =
38+
let open Fc.Infix_result_monad in
39+
Pgsql_io.Prepared_stmt.execute
40+
conn
41+
Pgsql_io.Typed_sql.(
42+
sql /^ Printf.sprintf "set idle_in_transaction_session_timeout='%s'" idle_tx_timeout)
43+
>>= fun () ->
44+
Pgsql_io.Prepared_stmt.execute conn Pgsql_io.Typed_sql.(sql /^ "set lock_timeout='60s'")
45+
>>= fun () ->
46+
Pgsql_io.Prepared_stmt.execute
47+
conn
48+
Pgsql_io.Typed_sql.(sql /^ "set statement_timeout='300s'")
49+
in
50+
let open Abb.Future.Infix_monad in
51+
go ()
4152
>>= function
4253
| Ok () -> Abb.Future.return ()
4354
| Error (#Pgsql_io.err as err) ->

0 commit comments

Comments
 (0)