question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OracleCommand does not respond to cancellation

See original GitHub issue

I 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:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
alexkehcommented, Nov 10, 2021

@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.

0reactions
madelsoncommented, Dec 12, 2021

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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found