Closed peter-villadsen closed 5 months ago
Hi @peter-villadsen, thanks for bringing this up, will post an update when fixed.
RichardIrons,
I tested the repro in the bug with a version of the Neo4j.Driver.Simple dll with the fix that has been merged into 5.0. I can see that the cancellationToken makes it to the place that has changed, but the system still does not react to the cancellationToken being canceled - No exception is being thrown. I notice that you have not closed out the bug yet, so there may be something I am missing?
The pull request does not add any tests for this scenario, so I only have my own test (in the bug) to work from.
Please advise, since I have a product I would like to ship with this feature.
@peter-villadsen Hi, the change was deployed on Monday to 5.17.0, it should allow the the driver to cancel the query, there is a known issue with supporting cancellation tokens in the driver.
The change @RichardIrons-neo4j implemented should allow for the query to be cancelled. Though the cancellation can only occur between each record being returned. I hope we can pick up full cancellation token support soon.
Apologies on the delay getting back to you about this.
Describe the bug The ExecuteAsync method on the IExecutableQuery interface does not terminate the query when the token is cancelled. Please see the sample below for a demonstration of this issue.
To Reproduce The repro has two steps: first the mechanics for the repro by using standard .NET features are described. Then the neo4j bits are introduced to show the problem.
Please consider this snippet:
As you can see, the program is a console app (running under ,NET 8). A timer is set up to fire after 10 seconds. A cancellationTokenSource is created, and it is cancelled when the timer fires. The token from this cancellationTokenSource is passed to the call Task.Delay() call, which runs for more than the 10 seconds. When it fires, the Delay method notices, and throws a TaskCanceledException exception.
Now some Neo4j relevant things are added to this template. Instead of just delaying, code is inserted to search for something in the database. The repro is complicated by the fact that a long-running query is needed to demonstrate the problem. Feel free to tweak the timing parameters to suit your needs.
The final demo looks like this:
The sample just accesses data with the long-running query (that has to run for more than 10 seconds in the code above). The issue in this bug is that the execution of the ExecuteAsync call does not in fact cause the query execution to end.
Expected behavior The expected behavior is that when the token is Cancelled (which is done when the timer runs out), the execution of the query should be aborted. This is what is described in the documentation comments for that method:
Version Info (please complete the following information):
Additional context Please advise about any supported ways of stopping a rogue query. I realize that it is possible to execute TERMINATE TRANSACTION, but that is clunky and the id can only be fetched through a SHOW TRANSACTIONS call, with appropriate filtering to determine the right query.
The code in the example is enclosed. Program.zip