diff --git a/tests/bugs/gh_8115_test.py b/tests/bugs/gh_8115_test.py index 99b68e96..46bfd252 100644 --- a/tests/bugs/gh_8115_test.py +++ b/tests/bugs/gh_8115_test.py @@ -14,6 +14,13 @@ NOTES: https://github.com/FirebirdSQL/firebird/commit/bbd35ab07c129e9735f081fcd29172a8187aa8ab Avoid reading/hashing the inner stream(s) if the leader stream is empty + [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"). + Checked on 6.0.0.457, 5.0.2.1499 """ import zipfile @@ -57,17 +64,29 @@ def test_1(act: Action, tmp_fbk: Path, capsys): with act.db.connect() as con: cur = con.cursor() - ps = cur.prepare(test_sql) - print( '\n'.join([replace_leading(s) for s in ps.detailed_plan.split('\n')]) ) - + ps, rs = None, None try: - cur.execute(ps) - for r in cur: + ps = cur.prepare(test_sql) + print( '\n'.join([replace_leading(s) for s in ps.detailed_plan.split('\n')]) ) + + # ::: NB ::: 'ps' returns data, i.e. this is SELECTABLE expression. + # We have to store result of cur.execute() 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: for p in r: print(p) except DatabaseError as e: print(e.__str__()) print(e.gds_codes) + finally: + if rs: + rs.close() # <<< EXPLICITLY CLOSING CURSOR RESULTS + if ps: + ps.free() expected_stdout_5x = """ Select Expression