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_6458_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:22:27 +03:00
parent 902f10a4fa
commit bdce103159

View File

@ -5,35 +5,41 @@ ID: issue-6691
ISSUE: 6691 ISSUE: 6691
TITLE: Regression: Cancel Query function no longer works TITLE: Regression: Cancel Query function no longer works
DESCRIPTION: DESCRIPTION:
We create .sql script with 'heavy query' that for sure will run more than several seconds. We create .sql script with 'heavy query' that for sure will run more than several seconds.
Then we launch asynchronously ISQL to perform this query and wait until its PID and running Then we launch asynchronously ISQL to perform this query and wait until its PID and running
query will appear in the mon$ tables (we are looking for query that containing text 'HEAVY_TAG'). query will appear in the mon$ tables (we are looking for query that containing text 'HEAVY_TAG').
After this we send signal CTRL_C_EVENT for emulating interruption that is done by pressing Ctrl-C. After this we send signal CTRL_C_EVENT for emulating interruption that is done by pressing Ctrl-C.
Then we wait for process finish (call wait() method) - this is necessary if ISQL will continue Then we wait for process finish (call wait() method) - this is necessary if ISQL will continue
without interruprion (i.e. if something will be broken again). without interruprion (i.e. if something will be broken again).
When method wait() will return control back, we can obtain info about whether child process was When method wait() will return control back, we can obtain info about whether child process was
terminated or no (using method poll()). If yes (expected) then it must return 1. terminated or no (using method poll()). If yes (expected) then it must return 1.
Finally, we check ISQL logs for STDOUT and STDERR. They must be as follows: Finally, we check ISQL logs for STDOUT and STDERR. They must be as follows:
* STDOUT -- must be empty * STDOUT -- must be empty
* STDERR -- must contain (at least) two phrases: * STDERR -- must contain (at least) two phrases:
1. Statement failed, SQLSTATE = HY008 1. Statement failed, SQLSTATE = HY008
2. operation was cancelled 2. operation was cancelled
::: NB :::
Windows only: subprocess.Popen() must have argument: creationflags = subprocess.CREATE_NEW_PROCESS_GROUP
Otherwise we can not send signal Ctrl_C_EVENT to the child process.
Linux: parameter 'creationflags' must be 0, signal.SIGINT is used instead of Ctrl_C_EVENT.
See: https://docs.python.org/2.7/library/subprocess.html
Confirmed bug on 4.0.0.2307: query could NOT be interrupted and we had to wait until it completed.
Checked on 4.0.0.2324 (SS/CS): works OK, query can be interrupted via sending Ctrl-C signal.
JIRA: CORE-6458
FBTEST: bugs.core_6458 FBTEST: bugs.core_6458
NOTES:
::: NB :::
Windows only: subprocess.Popen() must have argument: creationflags = subprocess.CREATE_NEW_PROCESS_GROUP
Otherwise we can not send signal Ctrl_C_EVENT to the child process.
Linux: parameter 'creationflags' must be 0, signal.SIGINT is used instead of Ctrl_C_EVENT.
See: https://docs.python.org/2.7/library/subprocess.html
Confirmed bug on 4.0.0.2307: query could NOT be interrupted and we had to wait until it completed.
Checked on 4.0.0.2324 (SS/CS): works OK, query can be interrupted via sending Ctrl-C signal.
[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 re import re
@ -100,28 +106,44 @@ def test_1(act: Action, heavy_script: Path, heavy_stdout: Path, heavy_stderr: Pa
tx_watcher = con_watcher.transaction_manager(custom_tpb) tx_watcher = con_watcher.transaction_manager(custom_tpb)
cur_watcher = tx_watcher.cursor() cur_watcher = tx_watcher.cursor()
ps = cur_watcher.prepare(chk_mon_sql) ps, rs = None, None
try:
ps = cur_watcher.prepare(chk_mon_sql)
i = 0 i = 0
da = dt.now() da = dt.now()
while True: while True:
cur_watcher.execute(ps, (p_heavy_sql.pid, HEAVY_TAG,) ) # ::: NB ::: 'ps' returns data, i.e. this is SELECTABLE expression.
mon_result = -1 # We have to store result of cur.execute(<psInstance>) in order to
for r in cur_watcher: # close it explicitly.
mon_result = r[0] # 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_watcher.execute(ps, (p_heavy_sql.pid, HEAVY_TAG,) )
mon_result = -1
for r in rs:
mon_result = r[0]
tx_watcher.commit() tx_watcher.commit()
db = dt.now() db = dt.now()
diff_ms = (db-da).seconds*1000 + (db-da).microseconds//1000 diff_ms = (db-da).seconds*1000 + (db-da).microseconds//1000
if mon_result == 1: if mon_result == 1:
found_in_mon_tables = True found_in_mon_tables = True
break break
elif diff_ms > MAX_WAIT_FOR_ISQL_PID_APPEARS_MS: elif diff_ms > MAX_WAIT_FOR_ISQL_PID_APPEARS_MS:
break break
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()
time.sleep(0.1)
ps.free()
assert found_in_mon_tables, f'Could not find attachment in mon$ tables for {MAX_WAIT_FOR_ISQL_PID_APPEARS_MS} ms.' assert found_in_mon_tables, f'Could not find attachment in mon$ tables for {MAX_WAIT_FOR_ISQL_PID_APPEARS_MS} ms.'