OracleCommand does not respond to cancellation
See original GitHub issueI am trying to cancel an oracle command which is calling sys.dbms_session.sleep
but the cancellation signal doesn’t seem to be working. Here’s the code:
var conn = new OracleConnection(connectionString);
conn.Open();
var command = conn.CreateCommand();
command.CommandText = @"
begin
sys.dbms_session.sleep(5);
end;";
var sw = Stopwatch.StartNew();
var cts = new CancellationTokenSource(delay: TimeSpan.FromSeconds(1));
cts.Token.Register(() => Console.WriteLine("canceled"));
var task = command.ExecuteNonQueryAsync(cts.Token);
try { await task; }
catch (Exception ex) { Console.WriteLine(ex.Message); } // ORA-01013: user requested cancel of current operation
Console.WriteLine(sw.Elapsed); // ~5s
The command does end up in a canceled error state, but it only transitions to that state AFTER the sleep has completed, which negates the benefit of canceling. I’m running into the same issue trying to cancel calls to DBMS_LOCK.REQUEST
.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Speed up cancellation signal to Oracle
I want avoid that by speeding up cancellation signal. I'm using OracleManagedDataAccess.
Read more >OracleCommand.Cancel Method (System.Data.OracleClient)
If there is nothing to cancel, nothing happens. However, if there is a command in process, and the attempt to cancel fails, no...
Read more >Cancel query not working in SQLDev 21.4.1
Hi After trying to cancel the execution of a long query, a message inform that it was cancelled but the actual worksheet hangs...
Read more >OracleCommand Class (System.Data.OracleClient)
The cancellation token may optionally be ignored. The default implementation invokes the synchronous ExecuteScalar() method and returns a completed task, ...
Read more >Cancel
When it is invoked, the Cancel method attempts to cancel the statement currently running on the connection that the OracleCommand object is using...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@madelson I talked with the ODP.NET dev team. This situation is one they have seen before. ODP.NET sends the cancellation call to the DB server fairly quickly. However, the PL/SQL engine itself seldom checks for these client cancellation messages, which is different from how SQL cancellations behave.
While I some on the client side would consider this a bug, the choice the PL/SQL team made means this behavior is by design. I plan to update the ODP.NET doc so that this is more clearly spelled out.
For anyone else who comes across this, it seems to be fixed in newer versions of Oracle itself (e. g. as of 19.0.0.0.0 it works as expected).