hutiefang76 opened a new pull request, #4184: URL: https://github.com/apache/hertzbeat/pull/4184
## What changed This closes the new JDBC connection when statement creation or statement setup fails in `JdbcCommonCollect`. The existing code closed cached JDBC connections on failure, but a freshly opened connection could remain open if `setReadOnly(true)`, `createStatement()`, `setQueryTimeout(...)`, or `setMaxRows(...)` threw before the method returned the statement. That path can leave PostgreSQL `PgConnection` instances waiting for finalization. ## Validation - Reproduced the leak with a regression test: before the fix, `JdbcCommonCollectTest#testCloseConnectionWhenCreateStatementFails` failed because `connection.close()` was not called. - `JAVA_HOME=$(/usr/libexec/java_home -v 26) ./mvnw -s <central-only-settings> -pl hertzbeat-collector/hertzbeat-collector-basic -am -Dtest=JdbcCommonCollectTest#testCloseConnectionWhenCreateStatementFails -Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false test` - `JAVA_HOME=$(/usr/libexec/java_home -v 26) ./mvnw -s <central-only-settings> -pl hertzbeat-collector/hertzbeat-collector-basic -am -Dtest=JdbcCommonCollectTest -Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false test` - `JAVA_HOME=$(/usr/libexec/java_home -v 26) ./mvnw -s <central-only-settings> -pl hertzbeat-collector/hertzbeat-collector-basic -am -Dsurefire.failIfNoSpecifiedTests=false -DfailIfNoTests=false test` - `git diff --check` Fixes #4181 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
