Skip to content

Add validateOnStaleSecs to validate idle connections on borrow - #163

Merged
rbygrave merged 1 commit into
mainfrom
feature/validateOnStaleSecs
Sep 18, 2026
Merged

rbygrave merged 1 commit into
mainfrom
feature/validateOnStaleSecs

Conversation

@rob-bygrave

Copy link
Copy Markdown
Collaborator

Introduce a new validateOnStaleSecs option controlling the maximum idle age (in seconds) after which a free connection is validated when borrowed from the pool. This is separate from the background heartbeat and catches connections that died between heartbeat cycles before they are handed to the application.

Behaviour of validateStaleMillis():

  • Explicit validateOnStaleSecs is honoured; 0 disables borrow-time validation.
  • When unset and the heartbeat is enabled, stale-on-borrow validation remains disabled (unchanged default behaviour).
  • When unset and the heartbeat is disabled (e.g. AWS Lambda), it defaults to min(100, maxInactiveTimeSecs) seconds instead of the previous maxInactiveTimeSecs + trimPoolFreqSecs.

Wires the setting through DataSourceBuilder, DataSourceConfig (copy, setDefaults merge, and properties load) and adds tests. Documents the option in the configuration reference, create-datasource-pool and connection-validation-best-practices guides, and the README Lambda section.

Introduce a new `validateOnStaleSecs` option controlling the maximum
idle age (in seconds) after which a free connection is validated when
borrowed from the pool. This is separate from the background heartbeat
and catches connections that died between heartbeat cycles before they
are handed to the application.

Behaviour of validateStaleMillis():
- Explicit validateOnStaleSecs is honoured; 0 disables borrow-time
  validation.
- When unset and the heartbeat is enabled, stale-on-borrow validation
  remains disabled (unchanged default behaviour).
- When unset and the heartbeat is disabled (e.g. AWS Lambda), it
  defaults to min(100, maxInactiveTimeSecs) seconds instead of the
  previous maxInactiveTimeSecs + trimPoolFreqSecs.

Wires the setting through DataSourceBuilder, DataSourceConfig (copy,
setDefaults merge, and properties load) and adds tests. Documents the
option in the configuration reference, create-datasource-pool and
connection-validation-best-practices guides, and the README Lambda
section.
@rob-bygrave rob-bygrave self-assigned this Sep 17, 2026
@rob-bygrave
rob-bygrave requested a review from rPraml September 17, 2026 23:05
@rbygrave rbygrave added this to the 10.16 milestone Sep 18, 2026
@rbygrave
rbygrave merged commit fef41b6 into main Sep 18, 2026
2 checks passed
@rbygrave
rbygrave deleted the feature/validateOnStaleSecs branch September 18, 2026 00:35
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.

2 participants