Skip to content

Commit 1d4bb79

Browse files
authored
fix(connection): SingleConnectionDataSource concurrent getConnection may have problems (#1914)
* fix concurrent * fix concurrent * fix concurrent
1 parent 8a2837a commit 1d4bb79

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

server/odc-core/src/main/java/com/oceanbase/odc/core/datasource/SingleConnectionDataSource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class SingleConnectionDataSource extends BaseClassBasedDataSource impleme
5858
private final boolean autoReconnect;
5959
@Setter
6060
private EventPublisher eventPublisher;
61-
protected Connection connection;
61+
protected volatile Connection connection;
6262
private final List<ConnectionInitializer> initializerList = new LinkedList<>();
6363
private Lock lock;
6464
@Setter
@@ -96,7 +96,7 @@ public Connection getConnection(String username, String password) throws SQLExce
9696
/**
9797
* Reset a {@code Connection}
9898
*/
99-
public void resetConnection() throws SQLException {
99+
public synchronized void resetConnection() throws SQLException {
100100
log.info("The connection will be reset soon");
101101
close();
102102
this.connection = null;
@@ -181,7 +181,7 @@ private void onConnectionReset(Connection connection) {
181181
}
182182
}
183183

184-
private Connection innerCreateConnection() throws SQLException {
184+
private synchronized Connection innerCreateConnection() throws SQLException {
185185
if (this.connection != null) {
186186
throw new IllegalStateException("Connection is not null");
187187
}

0 commit comments

Comments
 (0)