Skip to content

Commit 0a226c5

Browse files
committed
Removed auto-reconnect to prevent issues with transactions
1 parent a83a6c1 commit 0a226c5

File tree

1 file changed

+0
-33
lines changed

1 file changed

+0
-33
lines changed

async_postgres.lua

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ end
161161
---@field url string **readonly** connection url
162162
---@field connecting boolean **readonly** is client connecting to the database
163163
---@field closed boolean **readonly** is client closed (to change it to true use `:close()`)
164-
---@field maxRetries number maximum number of retries to reconnect to the database if connection was lost (set to 0 to disable)
165-
---@field private retryAttempted number number of attempts to reconnect to the database
166164
---@field private conn PGconn native connection object (do not use it directly, otherwise be careful not to store it anywhere else, otherwise closing connection will be impossible)
167165
---@field private queries { push: fun(self, q: PGQuery), prepend: fun(self, q: PGQuery), pop: (fun(self): PGQuery), size: fun(self): number } list of queries
168166
---@field package acquired boolean
@@ -274,39 +272,10 @@ function Client:wait()
274272
return self.conn:wait()
275273
end
276274

277-
--- Tries to reconnect to the database,
278-
--- if maximum number will be reached, we will stop trying to reconnect
279-
---
280-
--- WARNING! If number of attempts is exceeded, first query will be failed
281-
---@private
282-
function Client:tryReconnect()
283-
if self.retryAttempted < self.maxRetries and not self.closed then
284-
self.retryAttempted = self.retryAttempted + 1
285-
self:reset(function(ok)
286-
if not ok and not self:connected() then
287-
timer.Simple(5, function()
288-
self:tryReconnect()
289-
end)
290-
end
291-
end)
292-
else
293-
local query = self.queries:pop()
294-
query.callback(false, "connection to the databse was lost, maximum number of retries exceeded")
295-
end
296-
end
297-
298275
---@private
299276
---@param query PGQuery
300277
function Client:runQuery(query)
301278
local function callback(ok, result, errdata)
302-
-- if connection was lost, put query back into the queue (it was popped before)
303-
-- and try to reconnect
304-
if not ok and not self:connected() and self.retryAttempted < self.maxRetries then
305-
self.queries:prepend(query)
306-
self:tryReconnect()
307-
return
308-
end
309-
310279
xpcall(query.callback, ErrorNoHaltWithStack, ok, result, errdata)
311280
self:processQueue()
312281
end
@@ -680,8 +649,6 @@ function async_postgres.Client(url)
680649
url = url,
681650
connecting = false,
682651
queries = Queue.new(),
683-
maxRetries = math.huge,
684-
retryAttempted = 0,
685652
}, Client)
686653
end
687654

0 commit comments

Comments
 (0)