Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
fix: make Statement.cancel and Statement.setQueryTimeout thread safe #413
Statement.cancel was not thread-safe, thus query timeout from one statement might cancel subsequent statement.
The change introduces state tracking of a statement (ide, in-query, cancelling, cancelled), so out-of-order cancels can be detected and ignored.
There are two basic problems with .cancel handing:
The approach is to have
Note: this dance does not guarantee that cancel is indeed dispatched to the backend, however the case when "cancel request" is not dispatched should be very rare. The remaining race is due to OS signals. In other words, current implementation just waits till the "interrupt" signal is sent to the proper backend, however it does not wait till the signal is processed.
The approach here is to atomically
referenced this pull request
Oct 31, 2015
@vlsi I think it's sufficient to just ignore subsequent cancel requests. The use case of cancel is for cancel to be called from a different thread than the one that the statement is currently executing on. I can't see a use case for multiple cancels to be accepted. Furthermore this would add considerable complexity