-
Notifications
You must be signed in to change notification settings - Fork 49
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
fix: statement.cancel() waits for statement to finish #531
Conversation
ea7d86d
to
7f71b79
Compare
Object result = | ||
ConnectionProxy.this.pluginManager.execute( | ||
this.invokeOnClass, | ||
methodName, | ||
method.getName(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why methodName isn't good in this case?
() -> method.invoke(this.invokeOn, args), | ||
args); | ||
return proxyIfReturnTypeIsJdbcInterface(method.getReturnType(), result); | ||
} finally { | ||
try { | ||
this.LOCK.unlock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to check is lock has been acquired above?
7f71b79
to
446dce7
Compare
@@ -313,6 +315,14 @@ private boolean isDirectExecute(String methodName) { | |||
class JdbcInterfaceProxy implements InvocationHandler { | |||
private final Object invokeOn; | |||
private final Class<?> invokeOnClass; | |||
private final ReentrantLock LOCK = new ReentrantLock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable name shouldn't be all uppercase here.
@@ -313,6 +315,14 @@ private boolean isDirectExecute(String methodName) { | |||
class JdbcInterfaceProxy implements InvocationHandler { | |||
private final Object invokeOn; | |||
private final Class<?> invokeOnClass; | |||
private final ReentrantLock LOCK = new ReentrantLock(); | |||
|
|||
private final Set<String> NON_SYNCHRONIZED_METHODS = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
446dce7
to
11e7b4d
Compare
boolean locked = false; | ||
if (nonSynchronizedMethods.contains(methodName)) { | ||
this.lock.lock(); | ||
locked = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the built in checks, either isHeldByCurrentThread
or isLocked
@@ -313,6 +315,14 @@ private boolean isDirectExecute(String methodName) { | |||
class JdbcInterfaceProxy implements InvocationHandler { | |||
private final Object invokeOn; | |||
private final Class<?> invokeOnClass; | |||
private final ReentrantLock lock = new ReentrantLock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are using a lock to replace the synchronized keyword, which is a mutex. I think you need to make this static so the lock becomes a mutex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lock can't be static!
171ed4f
to
795352a
Compare
795352a
to
c1039ea
Compare
Summary
Fix statement.cancel() waiting for statement to finish
Description
When a long running query is executed and
statement.cancel()
is used to stop it, the driver will not immediately cancel the statement and will wait for it to finish instead. This PR replaces the synchronized block with a ReentrantLock.Addresses #527
Additional Reviewers