Skip to content

connection holds references to closed transactions forever? [PYFB78] #93

@firebird-automations

Description

@firebird-automations

Submitted by: Ehmmm (ehmmm.firebird)

On server I have a long running service which opens connection and then in endless loop starts transaction, gathers some data and closes transaction.
(More exactly the service has more threads, each of them has its own connection and endless loop with transactions.)
This service slowly consumes more and more memory.

Simple demo would look something like this:

con = fdb.connect(...)
while True:
cur = con.trans().cursor()
cur.execute(...)
cur.transaction.close()
sleep(...)

I think the problem is that con.trans() creates new Transaction object which is stored in con.transactions() and reference to this object is never released and that's why Python will never release memory of this Transaction even if it is closed for a long time.

One option is to close (and "forget") Connection. Then Python releases whole Connection with all transactions.

But my dirty solution of this issue is following:

...
tra = cur.transaction
tra.close()
for i in reversed(range(len(con._transactions))):
if con._transactions[i] == tra:
del con._transactions[i]
...

I'd like to hear your opinion.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions