Browse Source

Merge pull request #3 from seriyps/transaction_q_timeout

Add configurable timeout for transaction's  BEGIN/COMMIT/ROLLBACK
Yuri Zhloba 8 years ago
parent
commit
e734c5d6b6
2 changed files with 5 additions and 3 deletions
  1. 1 0
      src/epgsql_pool.app.src
  2. 4 3
      src/epgsql_pool.erl

+ 1 - 0
src/epgsql_pool.app.src

@@ -9,6 +9,7 @@
   {env, [
   {env, [
          {connection_timeout, 10000},
          {connection_timeout, 10000},
          {query_timeout, 10000},
          {query_timeout, 10000},
+         {transaction_timeout, 20000},
          {pooler_get_worker_timeout, 10000},
          {pooler_get_worker_timeout, 10000},
          {pooler_max_queue, 1000},
          {pooler_max_queue, 1000},
          {max_reconnect_timeout, 5000},
          {max_reconnect_timeout, 5000},

+ 4 - 3
src/epgsql_pool.erl

@@ -126,17 +126,18 @@ do_query(PoolName0, QueryTuple, Options) ->
 -spec transaction(pool_name(), fun()) -> epgsql:reply() | {error, term()}.
 -spec transaction(pool_name(), fun()) -> epgsql:reply() | {error, term()}.
 transaction(PoolName0, Fun) ->
 transaction(PoolName0, Fun) ->
     PoolName = epgsql_pool_utils:pool_name_to_atom(PoolName0),
     PoolName = epgsql_pool_utils:pool_name_to_atom(PoolName0),
+    Timeout = application:get_env(epgsql_pool, transaction_timeout, 20000),
     with_worker(
     with_worker(
       PoolName,
       PoolName,
       fun(Worker) ->
       fun(Worker) ->
               try
               try
-                  gen_server:call(Worker, {squery, "BEGIN"}),
+                  gen_server:call(Worker, {squery, "BEGIN"}, Timeout),
                   Result = Fun(Worker),
                   Result = Fun(Worker),
-                  gen_server:call(Worker, {squery, "COMMIT"}),
+                  gen_server:call(Worker, {squery, "COMMIT"}, Timeout),
                   Result
                   Result
               catch
               catch
                   Err:Reason ->
                   Err:Reason ->
-                      gen_server:call(Worker, {squery, "ROLLBACK"}),
+                      gen_server:call(Worker, {squery, "ROLLBACK"}, Timeout),
                       erlang:raise(Err, Reason, erlang:get_stacktrace())
                       erlang:raise(Err, Reason, erlang:get_stacktrace())
               end
               end
       end).
       end).