Skip to content

AG-305 - Use Connection.setNetworkTimeout as a hard backstop in ConnectionValidator#sqlValidator#184

Merged
barreiro merged 1 commit intoagroal:masterfrom
gastaldi:sql-validator-network-timeout
May 4, 2026
Merged

AG-305 - Use Connection.setNetworkTimeout as a hard backstop in ConnectionValidator#sqlValidator#184
barreiro merged 1 commit intoagroal:masterfrom
gastaldi:sql-validator-network-timeout

Conversation

@gastaldi
Copy link
Copy Markdown
Collaborator

@gastaldi gastaldi commented Apr 14, 2026

Statement.setQueryTimeout relies on the driver sending a cancel signal to the server, which may not work when the connection is stuck at the network level (e.g. network partition, firewall dropping packets).

Setting a network timeout on the socket ensures validation will return within the configured timeout regardless of server cooperation.

@graben
Copy link
Copy Markdown
Collaborator

graben commented Apr 14, 2026

Hi @gastaldi, just thinking about AgroalPropertiesReader. Actually only validation timeout is supported. It's also integrated into Spring-Boot starter to configure validator. Might worth thinking about a backwards compatible enhancement! 🤔

@gastaldi
Copy link
Copy Markdown
Collaborator Author

I've now introduced io.agroal.api.configuration.AgroalConnectionPoolConfiguration.ConnectionValidator#sqlValidator(java.lang.String, java.time.Duration, java.time.Duration) and kept the implementation in the existing methods

@gastaldi gastaldi force-pushed the sql-validator-network-timeout branch 2 times, most recently from bbd2479 to c4cd2e9 Compare April 14, 2026 17:23
@gastaldi gastaldi force-pushed the sql-validator-network-timeout branch 5 times, most recently from c729f92 to 5605419 Compare April 29, 2026 20:22
@gastaldi
Copy link
Copy Markdown
Collaborator Author

I can confirm that this method fixes quarkusio/quarkus#49976, I'll submit a PR using it in Quarkus meanwhile

@gastaldi gastaldi force-pushed the sql-validator-network-timeout branch from 5605419 to da5fc5b Compare April 29, 2026 22:14
@gastaldi gastaldi force-pushed the sql-validator-network-timeout branch from da5fc5b to 0944cba Compare April 29, 2026 22:21
@gastaldi gastaldi changed the title Use Connection.setNetworkTimeout as a hard backstop in sqlValidator AG-305 - Use Connection.setNetworkTimeout as a hard backstop in ConnectionValidator#sqlValidator Apr 29, 2026
@gastaldi gastaldi force-pushed the sql-validator-network-timeout branch 3 times, most recently from f6605c9 to 1197fe7 Compare May 3, 2026 15:16
@gastaldi gastaldi force-pushed the sql-validator-network-timeout branch 4 times, most recently from 4f06169 to 3dda541 Compare May 3, 2026 15:42
@gastaldi gastaldi force-pushed the sql-validator-network-timeout branch from 3dda541 to 9dc23f3 Compare May 3, 2026 15:53
@gastaldi gastaldi force-pushed the sql-validator-network-timeout branch from 9dc23f3 to f0eec65 Compare May 3, 2026 16:00
@gastaldi gastaldi requested review from graben and gsmet May 3, 2026 16:03
@gastaldi gastaldi force-pushed the sql-validator-network-timeout branch from f0eec65 to 7e752bb Compare May 3, 2026 16:05
Set a network timeout on the connection before executing the validation
SQL so that an unresponsive network cannot hang the pool indefinitely.
The network timeout is set higher than the query timeout (default +5s
buffer) to give setQueryTimeout a chance to cancel the statement cleanly
before the socket is forced closed.

Add a new sqlValidator overload that accepts an explicit network timeout
Duration for environments that need to tune the backstop independently.
@gastaldi gastaldi force-pushed the sql-validator-network-timeout branch from 7e752bb to 7ab2816 Compare May 3, 2026 16:07
@barreiro barreiro merged commit ebbf534 into agroal:master May 4, 2026
8 checks passed
@gastaldi gastaldi deleted the sql-validator-network-timeout branch May 4, 2026 11:12
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.

4 participants