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

Does context cancellation cancel the underlying query? #731

Closed
knadh opened this issue Jan 5, 2018 · 6 comments
Closed

Does context cancellation cancel the underlying query? #731

knadh opened this issue Jan 5, 2018 · 6 comments

Comments

@knadh
Copy link

knadh commented Jan 5, 2018

ctx, cancel := context.WithCancel(context.Background())

// Cancel 5 seconds in.
go func() {
	time.Sleep(time.Second * 5)
  	cancel()
}()

// This query should take 10 seconds to return.
rows, err := dbt.db.QueryContext(ctx, "SELECT v, SLEEP(10) FROM test LIMIT 1")
fmt.Println(rows, err)

After reading #496 and #608, I was under the impression that in the above example, the underlying query would get canceled mid-execution, but that doesn't seem to be the case. It still takes 10 seconds to return (and the query shows in MySQL process list), albeit with the error sql: Rows are closed. Does this mean that the driver isn't actually able to cancel the underlying query running on the server?

@shogo82148
Copy link
Contributor

Hi, I'm the author of #608.

Does this mean that the driver isn't actually able to cancel the underlying query running on the server?

Yes, my implement doesn't kill the query running on the server.
It is still on TODO status.

if v != 1 { // TODO: need to kill the query, and v should be 0.

@methane
Copy link
Member

methane commented Jan 6, 2018

FYI, you can limit query execution time via hint.
https://dev.mysql.com/doc/refman/5.7/en/optimizer-hints.html#optimizer-hints-execution-time

@methane methane closed this as completed Jan 6, 2018
@knadh
Copy link
Author

knadh commented Jan 6, 2018

@shogo82148 @methane Thanks.

@arthurnn
Copy link

arthurnn commented Mar 8, 2018

Are there any plans on fixing that TODO?

@jpcope
Copy link

jpcope commented Sep 12, 2019

Are there any plans on fixing that TODO?

#791

Looks like it is in a milestone btw. For others adding circuit breaking to services and find that queries persist in mysql, you may want to watch and react to these issues so the maintainers know there is interest.

Most of my peers expected this to work because they were more familiar with postgres where such workflows are known to work, are more easy to implement / are supported by the query session natively without making more connections.

For now I am documenting in my org that mysql is less friendly here and effective support for such a feature would warrant mysql server changing their connection interface.

A work around would be nice since we have so much using mysql at the moment. :-)

@pjebs
Copy link

pjebs commented Sep 28, 2019

https://medium.com/@rocketlaunchr.cloud/canceling-mysql-in-go-827ed8f83b30

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

No branches or pull requests

6 participants