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

fix: statement.cancel() waits for statement to finish #531

Merged
merged 1 commit into from
Feb 2, 2024

Conversation

crystall-bitquill
Copy link
Contributor

@crystall-bitquill crystall-bitquill commented Jan 16, 2024

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

Object result =
ConnectionProxy.this.pluginManager.execute(
this.invokeOnClass,
methodName,
method.getName(),
Copy link
Contributor

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();
Copy link
Contributor

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?

@@ -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();
Copy link
Contributor

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 =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

boolean locked = false;
if (nonSynchronizedMethods.contains(methodName)) {
this.lock.lock();
locked = true;
Copy link
Contributor

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

Copy link
Contributor

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();
Copy link
Contributor

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

Copy link
Contributor

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!

@crystall-bitquill crystall-bitquill merged commit df277b7 into awslabs:main Feb 2, 2024
1 check passed
@crystall-bitquill crystall-bitquill deleted the issue-527 branch February 2, 2024 00:04
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

Successfully merging this pull request may close these issues.

3 participants