@@ -144,14 +144,10 @@ function _M.setup_type_casting(pg)
144
144
pg :set_type_deserializer (1041 , " array_string" )
145
145
end
146
146
147
- function _M .setup_socket_timeouts (pg , statement_timeout )
148
- if not statement_timeout then
149
- statement_timeout = config [" postgresql" ][" statement_timeout" ]
150
- end
151
-
152
- -- Set socket timeouts based on the postgresql statement timeout, but defer
153
- -- to the statement timeout for better cleanup.
154
- local send_read_timeout = statement_timeout + 5000
147
+ function _M .setup_socket_timeouts (pg )
148
+ -- We'll assume statement_timeout should take precedence, so set a much
149
+ -- longer socket timeout to work with any customized statement timeout.
150
+ local send_read_timeout = 10 * 60 * 1000 -- 10 minutes
155
151
156
152
pg .sock :settimeouts (config [" postgresql" ][" connect_timeout" ], send_read_timeout , send_read_timeout )
157
153
end
@@ -224,13 +220,7 @@ function _M.query(query, values, options)
224
220
end
225
221
226
222
-- Allow custom timeouts to be specified for individual queries.
227
- --
228
- -- Note: Because the socket is actually shared, only longer timeout should
229
- -- probably be passed in here, since otherwise, this timeout may still apply
230
- -- on this same socket from other async queries happening.
231
223
if options and options [" statement_timeout" ] then
232
- _M .setup_socket_timeouts (pg , options [" statement_timeout" ])
233
-
234
224
local timeout_result , timeout_err = pg :query (" SET SESSION statement_timeout = " .. _M .escape_literal (options [" statement_timeout" ] .. " ms" ))
235
225
if not timeout_result then
236
226
ngx .log (ngx .ERR , " postgresql query error: " , timeout_err )
@@ -277,8 +267,6 @@ function _M.query(query, values, options)
277
267
278
268
-- If custom timeouts were specified, revert back to default timeouts.
279
269
if options and options [" statement_timeout" ] then
280
- _M .setup_socket_timeouts (pg )
281
-
282
270
local timeout_result , timeout_err = pg :query (" SET SESSION statement_timeout = " .. _M .escape_literal (config [" postgresql" ][" statement_timeout" ] .. " ms" ))
283
271
if not timeout_result then
284
272
ngx .log (ngx .ERR , " postgresql query error: " , timeout_err )
0 commit comments