6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 13:33:07 +01:00

Added/Updated tests\bugs\core_6048_test.py: Resultset of cursor that executes using instance of selectable PreparedStatement must be stored in some variable in order to have ability close it EXPLICITLY, before PS will be freed. Otherwise access violation can raises when Python runs garbage collection.

This commit is contained in:
pavel-zotov 2025-01-18 16:26:13 +03:00
parent bdce103159
commit da0580b307

View File

@ -33,6 +33,13 @@ NOTES:
::: NB-2 :::
Careful tuning required on each tesing box for this test.
[18.01.2025] pzotov
Resultset of cursor that executes using instance of selectable PreparedStatement must be stored
in some variable in order to have ability close it EXPLICITLY (before PS will be freed).
Otherwise access violation raises during Python GC and pytest hangs at final point (does not return control to OS).
This occurs at least for: Python 3.11.2 / pytest: 7.4.4 / firebird.driver: 1.10.6 / Firebird.Qa: 0.19.3
The reason of that was explained by Vlad, 26.10.24 17:42 ("oddities when use instances of selective statements").
"""
import os
@ -125,6 +132,9 @@ def test_1(act: Action, capsys):
print( e.__str__() )
cur2 = con2.cursor()
ps, rs = None, None
try:
ps = cur2.prepare('select mon$crypt_page, mon$crypt_state from mon$database')
# This will store different number of pages which are currently encrypted.
@ -140,8 +150,16 @@ def test_1(act: Action, capsys):
print(f'TIMEOUT EXPIRATION: encryption took {d1.seconds*1000 + d1.microseconds//1000} ms which exceeds limit = {MAX_WAITING_ENCR_FINISH} ms.')
break
cur2.execute(ps)
crypt_page, crypt_state = cur2.fetchone()
# ::: NB ::: 'ps' returns data, i.e. this is SELECTABLE expression.
# We have to store result of cur.execute(<psInstance>) in order to
# close it explicitly.
# Otherwise AV can occur during Python garbage collection and this
# causes pytest to hang on its final point.
# Explained by hvlad, email 26.10.24 17:42
rs = cur2.execute(ps)
for r in rs:
crypt_page, crypt_state = r[:2]
con2.commit()
# 0 = non crypted;
@ -157,7 +175,16 @@ def test_1(act: Action, capsys):
elif len(encrypting_pages_set) > ENCRYPTING_PAGES_MIN_CNT:
break
else:
time.sleep(0.5)
time.sleep(0.1)
except DatabaseError as e:
print( e.__str__() )
print(e.gds_codes)
finally:
if rs:
rs.close() # <<< EXPLICITLY CLOSING CURSOR RESULTS
if ps:
ps.free()
# ---------------------------------------------------------