Reputation: 13
We have a scenario where a web request is being cancelled, but the queries triggered by the request are still either fully resolving or retrying despise the parent request being cancelled.
Our query looks like the following:
var dbo = await _dbContext.GetDbMapper().SingleAsync<TDbEntity>(cql);
Looking through the source code of the project (https://github.com/datastax/csharp-driver-graph), I'm not able to find any way to use cancellation tokens.
So my question real boils down to what is the best way to cancel my get request.
If there is not an ideal way to do this, what would be the best way to contact the DataStax team regarding possibly submitting a PR to resolve this?
As a possible solution, we could do something like WithCancellation
to wrap the call and throw an exception upon timeout, but I think it would be more ideal to have the cancellation token go down the stack.
We are also working on limiting our retry policy to make the time after a cancelled request less impactful.
Upvotes: 1
Views: 191
Reputation: 712
This is indeed not supported by the driver and it is something that has been on our radar for a while.
Unfortunately this requires a substantial amount of changes to the public API of the driver so this is something that requires some design discussion before we are ready to accept/merge a PR. This also requires the commitment of some resources from our driver team to implement or review the API proposal (and PR) so anyone is free to create a JIRA and pick this up but it is important to expect that such a proposal/PR might take some time until it is actually reviewed and merged.
My suggestion would be to put together a proposal of the API changes that you'd like to see on the driver and then submit that proposal to the community. This can be done via JIRA or mailing list. Feel free to write the proposal on a different medium (like a google doc) if you prefer and attach it to the mailing list thread or JIRA issue.
You can also use a draft PR/branch as a way to represent the API changes of your proposal instead of writing an actual proposal but please avoid including internal driver code changes in that PR/branch so that the discussion can be focused on the API design at first. Also keep in mind that such proposal should cover all 3 components of the driver: LINQ, Mapper and Core (statements).
The internal implementation details can be figured out during the PR review process later after we have agreed on what the API will look like.
Upvotes: 2
Reputation: 16313
You can try something like:
var cancellationTokenSource = new CancellationTokenSource();
var task = session.ExecuteAsync(query, cancellationTokenSource.Token);
and then cancel the request with this call:
cancellationTokenSource.Cancel();
However, this might not work for your case because I think the underlying Cassandra C# driver in the Graph extension you referenced does not support cancellation tokens. I'm going to reach out to the driver devs who can correct me if I'm wrong and get them to respond.
In any case, all contributions are welcome and encouraged. The best way to get started is to create a ticket in the project's JIRA with details of your proposal and a link to your PR (if you have one). For details, see Contributing to the Cassandra C# driver. Cheers!
Upvotes: 1