A session that kills a busy one with ALTER SYSTEM KILL SESSION ... IMMEDIATE has its own connection closed (ORA-00031)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 57/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- python
- Lĩnh vực
- backend-api-design, database
Hướng nghiên cứu
Start by reading the ORA-00031 entry in src/oracledb/errors.py and how _check_and_raise_exception() uses ERR_ORACLE_ERROR_XREF; the report says the same error is also listed in ODPI-C’s connection-closing errors. Reproduce with the supplied script in Thin and Thick modes, then check that the killer reports ORA-00031 while remaining healthy and can run another statement. The report does not name a test file.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
- What versions are you using?
- Oracle Database 23ai Free 23.26.3.0.0 (container image)
- python-oracledb 26.1.0, Thin mode, and Thick mode with Oracle Instant Client 23.26.4.0.0: both behave the same way
- Python 3.14.10, Linux x86_64,
sys.maxsize > 2**32: True
- Is it an error or a hang or a crash?
An error: a healthy connection is closed by the driver.
- What error(s) or behavior you are seeing?
When a session kills another one that is busy in a call, with ALTER SYSTEM KILL SESSION '<sid>,<serial#>' IMMEDIATE,
the database answers the killer with ORA-00031 (session marked for kill): the target can't be ended at once, and
ends shortly after with ORA-00028. ORA-00031 is about the other session: the killer's own session is fine.
python-oracledb treats ORA-00031 as a dead session and closes the killer's connection:
killer: alter system kill session '58,49241' immediate
-> DPY-4011: the database or network closed the connection / ORA-00031: session marked for kill
is_healthy(): False
killer: select 'the killer still works' from dual
-> DPY-1001: not connected to database
is_healthy(): False
In Thick mode, the same, with DPI-1080: connection was closed by ORA-00031.
Expected: the killer gets ORA-00031 as an ordinary DatabaseError, and its connection remains usable. That's what
OCI does on its own: in a C program with OCI 23.26.4 (no ODPI-C), the killer gets ORA-00031,
OCI_ATTR_SERVER_STATUS stays OCI_SERVER_NORMAL, and its next statement works.
The cause seems to be the 31: ERR_CONNECTION_CLOSED entry in ERR_ORACLE_ERROR_XREF in
src/oracledb/errors.py, which makes _check_and_raise_exception() disconnect, and, in Thick mode, the same entry
in ODPI-C's list of errors that close the connection (DPI-1080). A session never gets ORA-00031 about itself
(killing the current session fails with ORA-00027), so it doesn't belong in these lists. With that line removed
from errors.py, Thin mode behaves as expected:
killer: alter system kill session '58,...' immediate
-> ORA-00031: session marked for kill
is_healthy(): True
victim: begin dbms_session.sleep(10); end;
-> DPY-4011: the database or network closed the connection / ORA-00028: session has been terminated / ...
is_healthy(): False
killer: select 'the killer still works' from dual
-> ok ('the killer still works',)
Applications that kill sessions (administration tools, watchdogs that end runaway queries) lose their own
connection, its transaction and its session state whenever the target is busy, which is the usual reason to kill
it; a pooled connection is dropped, and killing a second session on the same connection fails with DPY-1001. The
DPY-4011 message also suggests a network problem. Without IMMEDIATE, the killer gets no error (the database waits
for the target to end), so it isn't affected.
- Does your application call init_oracle_client()?
Both: Thin mode (no) and Thick mode (yes) are affected. The script below uses Thick mode when given an Instant Client
directory.
- Include a runnable Python script that shows the problem.
The user needs the ALTER SYSTEM privilege. No tables are needed.
"""
A session that kills a busy one with ALTER SYSTEM KILL SESSION ... IMMEDIATE gets ORA-00031 (session marked for
kill), and python-oracledb then closes the killer's own connection. Self-contained: python-oracledb only.
Usage: python repro_kill_session.py user password host:port/service [instant client lib dir: Thick mode]
The user needs the ALTER SYSTEM privilege. The session's serial number comes from DBMS_DEBUG_JDWP, which needs no
access to V$SESSION.
"""
import sys
import threading
import time
import oracledb
user, password, dsn = sys.argv[1:4]
if len(sys.argv) > 4:
oracledb.init_oracle_client(lib_dir=sys.argv[4])
def run(name, conn, sql):
try:
with conn.cursor() as cursor:
cursor.execute(sql)
row = cursor.fetchone() if cursor.description else None
outcome = f"ok {row}"
except oracledb.Error as e:
outcome = " / ".join(line for line in str(e).splitlines() if not line.startswith("Help:"))
print(f"{name}: {sql}\n -> {outcome}\n is_healthy(): {conn.is_healthy()}")
killer = oracledb.connect(user=user, password=password, dsn=dsn)
victim = oracledb.connect(user=user, password=password, dsn=dsn)
print(f"python-oracledb {oracledb.__version__}, thin={killer.thin}, database {killer.version}\n")
with victim.cursor() as cursor:
cursor.execute("select dbms_debug_jdwp.current_session_id || ',' || "
"dbms_debug_jdwp.current_session_serial from dual")
victim_session = cursor.fetchone()[0]
# The victim is busy for 10 seconds; the killer kills it after half a second
killer_thread = threading.Thread(
target=lambda: (time.sleep(0.5),
run("killer", killer, f"alter system kill session '{victim_session}' immediate"))
)
killer_thread.start()
run("victim", victim, "begin dbms_session.sleep(10); end;")
killer_thread.join()
# The killer's session is fine, but its connection is gone
run("killer", killer, "select 'the killer still works' from dual")
Output (Thin mode):
python-oracledb 26.1.0, thin=True, database 23.26.3.0.0
victim: begin dbms_session.sleep(10); end;
-> DPY-4011: the database or network closed the connection / ORA-00028: session has been terminated / ORA-06512: at "SYS.DBMS_SESSION", line 438 / ORA-06512: at line 1
is_healthy(): False
killer: alter system kill session '58,49241' immediate
-> DPY-4011: the database or network closed the connection / ORA-00031: session marked for kill
is_healthy(): False
killer: select 'the killer still works' from dual
-> DPY-1001: not connected to database
is_healthy(): False
Output (Thick mode):
python-oracledb 26.1.0, thin=False, database 23.26.3.0.0
victim: begin dbms_session.sleep(10); end;
-> DPY-4011: the database or network closed the connection / DPI-1080: connection was closed by ORA-00028 / ORA-00028: session has been terminated / ORA-06512: at "SYS.DBMS_SESSION", line 438 / ORA-06512: at line 1
is_healthy(): False
killer: alter system kill session '58,18807' immediate
-> DPY-4011: the database or network closed the connection / DPI-1080: connection was closed by ORA-00031 / ORA-00031: session marked for kill
is_healthy(): False
killer: select 'the killer still works' from dual
-> DPY-1001: not connected to database / DPI-1010: not connected
is_healthy(): False
- Ngôn ngữ chính
- Python
- Star
- 458
- Fork
- 123
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của oracle/python-oracledb
-
Free-threading supportĐang mởenhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
oracle/python-oracledb#642 · 1 bình luận ·
-
connection.gettype with large type def throws error: dbms_pickler: raw variable length too longĐang mởbug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
oracle/python-oracledb#641 · 6 bình luận ·
-
bug patch available
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 76/100
oracle/python-oracledb#640 · 4 bình luận ·
-
Client Library or Database
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
oracle/python-oracledb#637 · 2 bình luận ·
-
Client Library or Database
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 55/100
oracle/python-oracledb#633 · 2 bình luận ·
Tất cả issue của oracle/python-oracledb
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug improve content
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
opensafely/documentation#2102 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
difficulty:1 documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
MakazhanAlpamys/Soup#3533 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
onyx-dot-app/onyx#18730 ·
Maintainer thường phản hồi trong vòng 1 ngày