Skip to content

Commit

Permalink
修复bug:socketTimeout参数不支持mysql jdbcurl里设置socketTimeout=0的场景 alibaba#5451
Browse files Browse the repository at this point in the history
socketTimeout参数不支持mysql jdbcurl里设置socketTimeout=0的场景
  • Loading branch information
lizongbo committed Sep 29, 2023
1 parent 657642d commit 1fe13e0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
13 changes: 6 additions & 7 deletions core/src/main/java/com/alibaba/druid/pool/DruidDataSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -830,13 +830,6 @@ public void init() throws SQLException {
this.transactionIdSeedUpdater.addAndGet(this, delta);
}

if (this.jdbcUrl != null) {
this.jdbcUrl = this.jdbcUrl.trim();
initFromWrapDriverUrl();

initFromUrlOrProperties();
}

if (connectTimeout == 0) {
connectTimeout = DEFAULT_TIME_CONNECT_TIMEOUT_MILLIS;
}
Expand All @@ -845,6 +838,12 @@ public void init() throws SQLException {
socketTimeout = DEFAULT_TIME_SOCKET_TIMEOUT_MILLIS;
}

if (this.jdbcUrl != null) {
this.jdbcUrl = this.jdbcUrl.trim();
initFromWrapDriverUrl();
initFromUrlOrProperties();
}

for (Filter filter : filters) {
filter.init(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,22 @@ public void test1() throws Exception {
assertEquals(3000, ds.getConnectTimeout());
assertEquals(6000, ds.getSocketTimeout());
}

@Test
public void test_timeout_is_zero() throws Exception {
ds.setUrl("jdbc:mysql://127.0.0.1:3306/xxx?connectTimeout=0&socketTimeout=0");
ds.init();
assertEquals(0, ds.getConnectTimeout());
assertEquals(0, ds.getSocketTimeout());
}
@Test
public void test_timeout_is_zero2() throws Exception {
ds.setUrl("jdbc:mysql://127.0.0.1:3306/xxx");
ds.setConnectTimeout(-1);
ds.setSocketTimeout(-1);
ds.init();
assertEquals(-1, ds.getConnectTimeout());
assertEquals(-1, ds.getSocketTimeout());
}
@Test
public void test2() throws Exception {
Properties properties = new Properties();
Expand Down

0 comments on commit 1fe13e0

Please sign in to comment.