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_5646_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:31:16 +03:00
parent da0580b307
commit 9ea5d26d92

View File

@ -70,7 +70,6 @@ NOTES:
9 ::: [232976, 917504, 232976, 917504] 9 ::: [232976, 917504, 232976, 917504]
10 ::: [232976, 983040, 232976, 983040] 10 ::: [232976, 983040, 232976, 983040]
4.0.0.840, 02-jan-2018 4.0.0.840, 02-jan-2018
====================== ======================
differences: differences:
@ -86,6 +85,12 @@ NOTES:
9 ::: [ 0, 0, 0, 0] 9 ::: [ 0, 0, 0, 0]
10 ::: [ 0, 0, 0, 0] 10 ::: [ 0, 0, 0, 0]
[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 pytest import pytest
@ -418,29 +423,44 @@ def test_1(act: Action, capsys):
""" """
with con_worker.cursor() as cur_worker, con_dba.cursor() as cur_dba: with con_worker.cursor() as cur_worker, con_dba.cursor() as cur_dba:
ps, rs = None, None
try:
ps = cur_dba.prepare(sql_memory_usage) ps = cur_dba.prepare(sql_memory_usage)
for i in range(N_MEASURES): for i in range(N_MEASURES):
cur_dba.execute(ps) # ::: NB ::: 'ps' returns data, i.e. this is SELECTABLE expression.
for r in cur_dba: # 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_dba.execute(ps)
for r in rs:
memory_diff[ i ] = r[1:] memory_diff[ i ] = r[1:]
try: try:
# nb: EVERY run we force engine to compile NEW query because of changing 'i': # nb: EVERY run we force engine to compile NEW query because of changing 'i':
px = cur_worker.prepare(bad_sql % locals()) px = cur_worker.prepare(bad_sql % locals())
except DatabaseError as e: except DatabaseError as x:
pass pass
con_dba.commit() con_dba.commit()
cur_dba.execute(ps) rs = cur_dba.execute(ps)
for r in cur_dba: for r in rs:
# Make subtraction for elements with same indices. # Make subtraction for elements with same indices.
# This is DIFFERENCE between values in mon$memory_usage columns # This is DIFFERENCE between values in mon$memory_usage columns
# gathered after and before each measure: # gathered after and before each measure:
# #
memory_diff[ i ] = [a - b for a, b in zip(r[1:], memory_diff[ i ])] memory_diff[ i ] = [a - b for a, b in zip(r[1:], memory_diff[ i ])]
except DatabaseError as e:
print( e.__str__() )
print(e.gds_codes)
finally:
if rs:
rs.close() # <<< EXPLICITLY CLOSING CURSOR RESULTS
if ps:
ps.free()
memo_used_diff_list = [ v[0] for v in memory_diff.values() ] memo_used_diff_list = [ v[0] for v in memory_diff.values() ]
memo_allo_diff_list = [ v[1] for v in memory_diff.values() ] memo_allo_diff_list = [ v[1] for v in memory_diff.values() ]