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

Added/Updated tests\bugs\gh_6947_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:18:15 +03:00
parent 1fc6791847
commit 902f10a4fa

View File

@ -28,6 +28,13 @@ NOTES:
[11.03.2023] pzotov [11.03.2023] pzotov
Marked as SKIPPED because covered by core_6048_test. Marked as SKIPPED because covered by core_6048_test.
Probably will be deleted soon. Probably will be deleted soon.
[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 import os
import datetime as py_dt import datetime as py_dt
@ -118,8 +125,9 @@ def test_1(act: Action, capsys):
cur = con.cursor() cur = con.cursor()
cu2 = con.cursor() cu2 = con.cursor()
ps, rs = None, None
try:
ps = cur.prepare('select mon$crypt_page from mon$database') ps = cur.prepare('select mon$crypt_page from mon$database')
while encryption_started: while encryption_started:
t2=py_dt.datetime.now() t2=py_dt.datetime.now()
d1=t2-t1 d1=t2-t1
@ -127,8 +135,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.') print(f'TIMEOUT EXPIRATION: encryption took {d1.seconds*1000 + d1.microseconds//1000} ms which exceeds limit = {MAX_WAITING_ENCR_FINISH} ms.')
break break
cur.execute(ps) # ::: NB ::: 'ps' returns data, i.e. this is SELECTABLE expression.
p = cur.fetchone()[0] # 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 = cur.execute(ps)
for r in rs:
p = r[0]
cu2.callproc('sp_tmp', [ p, ] ) cu2.callproc('sp_tmp', [ p, ] )
con.commit() con.commit()
@ -150,6 +166,16 @@ def test_1(act: Action, capsys):
break break
act.reset() act.reset()
except DatabaseError as e:
print( e.__str__() )
print(e.gds_codes)
finally:
if rs:
rs.close() # <<< EXPLICITLY CLOSING CURSOR RESULTS
if ps:
ps.free()
if encryption_started: if encryption_started:
if len(encrypted_pages_set) >= MIN_DISTINCT_ENCRYPTED_PAGES: if len(encrypted_pages_set) >= MIN_DISTINCT_ENCRYPTED_PAGES:
print(expected_stdout) print(expected_stdout)