Oracle JDBC Thin Driver ↔ Database Resource Manager: Cancellation and Timeout Interoperability
0 reputation · 30 Sept 2021, 16:28 UTC
0 reputation · 30 Sept 2021, 16:28 UTC
Integrating the Oracle JDBC Thin driver with the database Resource Manager requires a clear understanding of how session termination is handled when multiple timeout mechanisms overlap. Specifically, the JDBC driver provides setQueryTimeout and the cancel() method to signal the server to abort execution via a break message.
Simultaneously, the Oracle Database Resource Manager can enforce hard limits on execution time using parameters such as MAX_EST_EXEC_TIME within a consumer group. When a session is subject to both a client-side JDBC timeout and a server-side Resource Manager limit, the priority and cleanup behavior of these two signals are not fully defined.
There is uncertainty regarding whether a JDBC cancel() request overrides the Resource Manager's enforced termination or if the two mechanisms operate independently, potentially leading to inconsistent resource release or lingering sessions in V$SESSION.
cancel() signal take precedence over a Resource Manager MAX_EST_EXEC_TIME limit, or does the server process the first signal received?32775 reputation · 01 Oct 2021, 01:13 UTC
There is no documented precedence rule between a JDBC cancel()/setQueryTimeout break and a Resource Manager MAX_EST_EXEC_TIME kill. They are independent mechanisms that act on the same session, and the server processes whichever signal it handles first. In practice the JDBC break usually arrives first — it is a single out-of-band network message — while Resource Manager enforcement happens on a periodic evaluation cycle (roughly 1–3 seconds in 19c/21c, up to 60 seconds in pre-12c releases). That is a timing artifact, not a guarantee you should design around.
On the second question: lock release is not deferred to a Resource Manager cleanup cycle. Whichever mechanism terminates the session, the server performs an implicit rollback of the active transaction and releases its row and table locks as part of termination processing. What is deferred is the disappearance of the row from V$SESSION: the session shows STATUS='KILLED' until PMON's periodic cleanup runs (a few seconds in current releases). That behavior is identical regardless of which side initiated the kill.
The JDBC Thin driver implements cancel() (and the timer behind setQueryTimeout) by sending an out-of-band break over a separate TCP connection, handled by the server's network layer. Resource Manager limits are enforced by background processes that periodically scan consumer-group state. Neither path checks whether the other has already fired; the first one to reach the session's execution context wins, and the second becomes a no-op on an already-dying session.
One asymmetry matters: MAX_EST_EXEC_TIME is evaluated against the optimizer's estimated execution time, not elapsed wall-clock time. A bad cardinality estimate can kill a query that would have finished in seconds, and some operations (DDL, PL/SQL blocks, certain parallel executions) may not get an estimate at all and bypass the limit. setQueryTimeout, by contrast, measures actual elapsed time on the client — and can itself be delayed by client-side GC pauses or a stalled network.
V$SESSION.STATUS and BLOCKING_SESSION.To confirm behavior on your exact version, run a controlled test: set MAX_EST_EXEC_TIME to 10 seconds and setQueryTimeout to 5, run a long query, then repeat with the values reversed. Correlate the results with:
-- Session state transitions and lock holding
SELECT sid, status, blocking_session, last_call_et FROM v$session WHERE ...;
-- Resource Manager view of the session (19c+)
SELECT sid, current_consumer_group, current_undo_consumption
FROM v$rsrc_session_info WHERE ...;The alert log distinguishes the two paths ("Resource Manager: terminating session" versus a received break), and a SQL trace (event 10046) shows the corresponding server-side stack if you need definitive proof. On 19c and later, DBA_HIST_RESOURCE_LIMIT and V$RSRC_SESSION_INFO help post-mortem correlation; on older releases you rely on the alert log and trace files.
This behavior is version-sensitive — Resource Manager evaluation intervals changed significantly between pre-12c and 19c+ — and the exact interaction is not formally documented by Oracle, so the precedence observations above reflect well-established behavior rather than a contractual guarantee. Verify on your target release before relying on either mechanism alone.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.