You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by li...@apache.org on 2024/01/03 13:35:04 UTC
(arrow-adbc) branch main updated: fix(java/driver/jdbc): fix connection leak in `JdbcDataSourceDatabase` constructor (#1418)
This is an automated email from the ASF dual-hosted git repository.
lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git
The following commit(s) were added to refs/heads/main by this push:
new 61c9236a fix(java/driver/jdbc): fix connection leak in `JdbcDataSourceDatabase` constructor (#1418)
61c9236a is described below
commit 61c9236a822b01748dd66dfa4d340a6d236d416e
Author: rtadepalli <10...@users.noreply.github.com>
AuthorDate: Wed Jan 3 08:34:58 2024 -0500
fix(java/driver/jdbc): fix connection leak in `JdbcDataSourceDatabase` constructor (#1418)
I think there is a connection leak in the constructor for
`JdbcDataSourceDatabase` where we're obtaining a connection in the
constructor but we're obtaining another one in the `connect` method
using the appropriate username/password. We can remove this and fix the
bug as described in #1415.
Fixes #1415.
---
.../adbc/driver/jdbc/JdbcDataSourceDatabase.java | 24 +++++++++++-----------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/java/driver/jdbc/src/main/java/org/apache/arrow/adbc/driver/jdbc/JdbcDataSourceDatabase.java b/java/driver/jdbc/src/main/java/org/apache/arrow/adbc/driver/jdbc/JdbcDataSourceDatabase.java
index 4059759b..6348e05c 100644
--- a/java/driver/jdbc/src/main/java/org/apache/arrow/adbc/driver/jdbc/JdbcDataSourceDatabase.java
+++ b/java/driver/jdbc/src/main/java/org/apache/arrow/adbc/driver/jdbc/JdbcDataSourceDatabase.java
@@ -34,8 +34,8 @@ public final class JdbcDataSourceDatabase implements AdbcDatabase {
private final String username;
private final String password;
private final JdbcQuirks quirks;
- private final Connection connection;
private final AtomicInteger counter;
+ private Connection connection;
JdbcDataSourceDatabase(
BufferAllocator allocator,
@@ -49,22 +49,19 @@ public final class JdbcDataSourceDatabase implements AdbcDatabase {
this.username = username;
this.password = password;
this.quirks = Objects.requireNonNull(quirks);
- try {
- this.connection = dataSource.getConnection();
- } catch (SQLException e) {
- throw JdbcDriverUtil.fromSqlException(e);
- }
+ this.connection = null;
this.counter = new AtomicInteger();
}
@Override
public AdbcConnection connect() throws AdbcException {
- final Connection connection;
try {
- if (username != null && password != null) {
- connection = dataSource.getConnection(username, password);
- } else {
- connection = dataSource.getConnection();
+ if (connection == null) {
+ if (username != null && password != null) {
+ connection = dataSource.getConnection(username, password);
+ } else {
+ connection = dataSource.getConnection();
+ }
}
} catch (SQLException e) {
throw JdbcDriverUtil.fromSqlException(e);
@@ -79,7 +76,10 @@ public final class JdbcDataSourceDatabase implements AdbcDatabase {
@Override
public void close() throws Exception {
- connection.close();
+ if (connection != null) {
+ connection.close();
+ }
+ connection = null;
}
@Override