Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement cancellation of active reader #3

Closed
bgrainger opened this issue Mar 31, 2016 · 3 comments
Closed

Implement cancellation of active reader #3

bgrainger opened this issue Mar 31, 2016 · 3 comments
Assignees
Milestone

Comments

@bgrainger
Copy link
Member

The consumer should be able to cancel an active reader via MySqlCommand.Cancel() or the CancellationToken passed to ExecuteReaderAsync etc.

This probably needs to be implemented via KILL QUERY which may require a separate connection. It may be helpful to implement connection pooling #2 first and keep a spare connection around to issue this command.

@bgrainger
Copy link
Member Author

KILL QUERY on a second connection won't necessarily work in an environment of load-balanced secondaries; the second connection might be to a different physical server, which can't cancel the query running on the first server.

Is there any way the query can be canceled using the connection that's already open?

@bgrainger
Copy link
Member Author

My assumption is that the consumer would expect the active command to be cancelled (cooperatively by the database) and that the connection would remain usable afterwards. Thus, we cannot implement cancellation by passing the CancellationToken down to the Socket methods and close the socket; it has to be handled at a higher level by executing KILL QUERY on a separate thread. (This will cause MySQL to return an error packet, which will need to be turned into a MySqlException or an OperationCanceledException depending on the mechanism of cancellation: DbCommand.Cancel or cancelling a CancellationToken.)

More specifically, the methods that expose cancellation are:

  • MySqlCommand.Cancel
  • MySqlCommand.ExecuteNonQueryAsync
  • MySqlCommand.ExecuteScalarAsync
  • MySqlCommand.ExecuteReaderAsync
  • MySqlDataReader.ReadAsync
  • MySqlDataReader.NextResultAsync

Handling the cancellation of a CancellationToken and calling DbCommand.Cancel (from another thread) can be implemented in a common fashion. (It may be possible to do something like (pseudocode) cancellationToken.Register(command.Cancel).)

bgrainger added a commit that referenced this issue Apr 11, 2017
Implement reader cancellation. Fixes #3
@bgrainger
Copy link
Member Author

Shipped in 0.17.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant