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

Expected Behavior of Abort with the AWS JDBC Wrapper #1173

Open
kiichiro-ito opened this issue Oct 31, 2024 · 2 comments · Fixed by #1182
Open

Expected Behavior of Abort with the AWS JDBC Wrapper #1173

kiichiro-ito opened this issue Oct 31, 2024 · 2 comments · Fixed by #1182
Assignees

Comments

@kiichiro-ito
Copy link

I'm developing an application that connects to PostgreSQL via JDBC using Spring Boot and HikariCP.

When attempting to stop the application (sending SIGINT) while a long-running query is active, it seems that HikariCP waits for the query to complete before aborting the connection. This behavior appears to be related to the AWS JDBC Wrapper's implementation:
(https://github.com/aws/aws-advanced-jdbc-wrapper/blob/main/wrapper/src/main/java/software/amazon/jdbc/util/WrapperUtils.java#L186)

In contrast, when using only the standard PostgreSQL driver, the connection is forcibly terminated even if a long-running query is in progress.

Question:
Is there a configuration or method to avoid this behavior?
According to the java.sql.Connection#abort specification, the connection should be forcibly terminated.

Thank you.

@aaron-congo
Copy link
Contributor

aaron-congo commented Nov 6, 2024

Hi @kiichiro-ito, thank you for reaching out and raising this issue. Could you please clarify whether you are interrupting the long-running query with Connection.abort or by executing kill -SIGINT <PID> on the command line? I'm assuming the former, since from my testing kill -SIGINT<PID> ends the application immediately but Connection.abort with our wrapper driver seems to wait until the query finishes like you mentioned. Let me know, and in the meantime I will keep investigating. Thanks!

@aaron-congo aaron-congo self-assigned this Nov 6, 2024
@kiichiro-ito
Copy link
Author

kiichiro-ito commented Nov 7, 2024

Hi @aaron-congo. Thanks for your response!

I'm sending kill -SIGINT <PID> to a Spring Boot application, which ultimately triggers Connection.abort.

When Spring Boot receives a SIGINT, SpringApplicationShutdownHook runs in the background. This hook initiates the shutdown process, which calls HikariDataSource.shutdown and eventually leads to Connection.abort.

Below is a thread dump captured during this behavior.

"SpringApplicationShutdownHook" #16 prio=5 os_prio=0 cpu=15.62ms elapsed=11.09s tid=0x000002070f1bb730 nid=0x55e0 waiting on condition  [0x000000a528ffe000]
   java.lang.Thread.State: WAITING (parking)
        at jdk.internal.misc.Unsafe.park([email protected]/Native Method)
        - parking to wait for  <0x00000006092d2bd0> (a java.util.concurrent.locks.ReentrantLock$NonfairSync)
        at java.util.concurrent.locks.LockSupport.park([email protected]/LockSupport.java:211)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire([email protected]/AbstractQueuedSynchronizer.java:715)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire([email protected]/AbstractQueuedSynchronizer.java:938)
        at java.util.concurrent.locks.ReentrantLock$Sync.lock([email protected]/ReentrantLock.java:153)
        at java.util.concurrent.locks.ReentrantLock.lock([email protected]/ReentrantLock.java:322)
        at software.amazon.jdbc.ConnectionPluginManager.lock(ConnectionPluginManager.java:158)
        at software.amazon.jdbc.util.WrapperUtils.executeWithPlugins(WrapperUtils.java:234)
        at software.amazon.jdbc.util.WrapperUtils.runWithPlugins(WrapperUtils.java:165)
        at software.amazon.jdbc.wrapper.ConnectionWrapper.abort(ConnectionWrapper.java:180)
        at com.zaxxer.hikari.pool.HikariPool.abortActiveConnections(HikariPool.java:535)
        at com.zaxxer.hikari.pool.HikariPool.shutdown(HikariPool.java:230)
        - locked <0x0000000609b8abc0> (a com.zaxxer.hikari.pool.HikariPool)
        at com.zaxxer.hikari.HikariDataSource.close(HikariDataSource.java:351)
        at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:232)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:587)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:559)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:1202)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:520)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:1195)
        at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1183)
        at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1144)
        at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1090)
        at org.springframework.boot.SpringApplicationShutdownHook.closeAndWait(SpringApplicationShutdownHook.java:145)
        at org.springframework.boot.SpringApplicationShutdownHook$$Lambda$857/0x00000206ca5cfc08.accept(Unknown Source)
        at java.lang.Iterable.forEach([email protected]/Iterable.java:75)
        at org.springframework.boot.SpringApplicationShutdownHook.run(SpringApplicationShutdownHook.java:114)
        at java.lang.Thread.run([email protected]/Thread.java:833)

Maven dependencies:

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>3.3.0</version>
		<relativePath /> 
	</parent>
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-aop</artifactId>
		</dependency>
		<dependency>
			<groupId>org.mybatis.spring.boot</groupId>
			<artifactId>mybatis-spring-boot-starter</artifactId>
			<version>3.0.3</version>
		</dependency>		
		<dependency>
			<groupId>org.postgresql</groupId>
			<artifactId>postgresql</artifactId>
			</dependency>
		<dependency>
			<groupId>software.amazon.jdbc</groupId>
			<artifactId>aws-advanced-jdbc-wrapper</artifactId>
			<version>2.4.0</version>
		</dependency>
	</dependencies>

thank you.

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 a pull request may close this issue.

2 participants