SQLProvider icon indicating copy to clipboard operation
SQLProvider copied to clipboard

Any support for cancellation tokens?

Open OnurGumus opened this issue 4 years ago • 3 comments

In the api , I am not seeing any support for cancellation. Is it possible to cancel long running queries ?

OnurGumus avatar Apr 26 '20 17:04 OnurGumus

There is timeout parameter for .GetDataContext method.

If you use Async methods, you could do your own:

module Async =
  /// Async.Start with timeout in seconds
  let StartWithTimeout (timeoutSecs:int) (computation:Async<unit>) =
    let c = new System.Threading.CancellationTokenSource(timeoutSecs*1000)
    Async.Start(computation, cancellationToken = c.Token)

...however the query will run in the end in the background. I don't know if there is database-specific commands to cancel execution. SQLProvider can commit to transactions, so cancelling a query should also roll-back the transaction.

Thorium avatar May 01 '20 09:05 Thorium

There is a DBCommand.Cancel. https://docs.microsoft.com/en-us/dotnet/api/system.data.common.dbcommand.cancel?view=net-5.0 So perhaps this could be utilized.

OnurGumus avatar Jan 03 '21 09:01 OnurGumus

My concern is let's say there is a DB query running potentially long, and we want to give the opportunity to cancel to the client so that the query won't be exhausting DB resources or to make sure the the query/trx is cancelled

OnurGumus avatar Jan 03 '21 09:01 OnurGumus