Skip to content

Commit e06c31e

Browse files
author
diego Dupin
committed
[CONJ-911] enable keep-alive by default
1 parent 6f8f13b commit e06c31e

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

src/main/java/org/mariadb/jdbc/Configuration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class Configuration {
7373
DriverManager.getLoginTimeout() > 0 ? DriverManager.getLoginTimeout() * 1000 : 30_000;
7474
private String pipe = null;
7575
private String localSocket = null;
76-
private boolean tcpKeepAlive = false;
76+
private boolean tcpKeepAlive = true;
7777
private int tcpKeepIdle = 0;
7878
private int tcpKeepCount = 0;
7979
private int tcpKeepInterval = 0;

src/main/resources/driver.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ socketFactory=to use a custom socket factory, set it to the full name of the cla
55
connectTimeout=The connect timeout value, in milliseconds, or zero for no timeout.
66
pipe=On Windows, specify named pipe name to connect.
77
localSocket=Permits connecting to the database via Unix domain socket, if the server allows it. The value is the path of Unix domain socket (i.e "socket" database parameter : select @@socket)
8-
tcpKeepAlive=Sets corresponding option on the connection socket.
8+
tcpKeepAlive=Sets corresponding option on the connection socket. Default: True
99
tcpAbortiveClose=This option can be used in environments where connections are created and closed in rapid succession. Often, it is not possible to create a socket in such an environment after a while, since all local �ephemeral� ports are used up by TCP connections in TCP_WAIT state. Using tcpAbortiveClose works around this problem by resetting TCP connections (abortive or hard close) rather than doing an orderly close. It is accomplished by using socket.setSoLinger(true,0) for abortive close
1010
localSocketAddress=Hostname or IP address to bind the connection socket to a local (UNIX domain) socket.
1111
socketTimeout=Defined the network socket timeout (SO_TIMEOUT) in milliseconds. Value of 0 disables this timeout.If the goal is to set a timeout for all queries, since MariaDB 10.1.1, the server has permitted a solution to limit the query time by setting a system variable, max_statement_time. The advantage is that the connection then is still usable. Default: 0ms.

src/test/java/org/mariadb/jdbc/integration/ConnectionTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ public void isValid() throws SQLException {
3030
assertFalse(sharedConn.isValid(2000));
3131
}
3232

33+
@Test
34+
public void tcpKeepAlive() throws SQLException {
35+
try (Connection con = createCon("&tcpKeepAlive=false")) {
36+
con.isValid(1);
37+
}
38+
}
39+
3340
@Test
3441
void isValidWrongValue() {
3542
try {

src/test/java/org/mariadb/jdbc/unit/util/ConfigurationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ public void builder() throws SQLException {
759759
.restrictedAuth("mysql_native_password,client_ed25519")
760760
.pipe("pipeName")
761761
.localSocket("localSocket")
762-
.tcpKeepAlive(true)
762+
.tcpKeepAlive(false)
763763
.tcpAbortiveClose(true)
764764
.localSocketAddress("localSocketAddress")
765765
.socketTimeout(1000)
@@ -814,7 +814,7 @@ public void builder() throws SQLException {
814814
.allowPublicKeyRetrieval(true)
815815
.build();
816816
assertEquals(
817-
"jdbc:mariadb://host1:3305,address=(host=host2)(port=3307)(type=replica)/db?user=me&password=pwd&timezone=UTC&autocommit=false&defaultFetchSize=10&maxQuerySizeToLog=100&geometryDefaultType=default&restrictedAuth=mysql_native_password,client_ed25519&socketFactory=someSocketFactory&connectTimeout=22&pipe=pipeName&localSocket=localSocket&tcpKeepAlive=true&tcpKeepIdle=10&tcpKeepCount=50&tcpKeepInterval=50&tcpAbortiveClose=true&localSocketAddress=localSocketAddress&socketTimeout=1000&useReadAheadInput=false&tlsSocketType=TLStype&sslMode=TRUST&serverSslCert=mycertPath&keyStore=/tmp&keyStorePassword=MyPWD&keyStoreType=JKS&enabledSslCipherSuites=myCipher,cipher2&enabledSslProtocolSuites=TLSv1.2&allowMultiQueries=true&allowLocalInfile=true&useCompression=true&useAffectedRows=true&useBulkStmts=false&cachePrepStmts=false&prepStmtCacheSize=2&useServerPrepStmts=true&credentialType=ENV&sessionVariables=blabla&connectionAttributes=bla=bla&servicePrincipalName=SPN&blankTableNameMeta=true&tinyInt1isBit=false&yearIsDateType=false&dumpQueriesOnException=true&includeInnodbStatusInDeadlockExceptions=true&includeThreadDumpInDeadlockExceptions=true&retriesAllDown=10&galeraAllowedState=A,B&transactionReplay=true&pool=true&poolName=myPool&maxPoolSize=16&minPoolSize=12&maxIdleTime=25000&registerJmxPool=false&poolValidMinDelay=260&useResetConnection=true&serverRsaPublicKeyFile=RSAPath&allowPublicKeyRetrieval=true",
817+
"jdbc:mariadb://host1:3305,address=(host=host2)(port=3307)(type=replica)/db?user=me&password=pwd&timezone=UTC&autocommit=false&defaultFetchSize=10&maxQuerySizeToLog=100&geometryDefaultType=default&restrictedAuth=mysql_native_password,client_ed25519&socketFactory=someSocketFactory&connectTimeout=22&pipe=pipeName&localSocket=localSocket&tcpKeepAlive=false&tcpKeepIdle=10&tcpKeepCount=50&tcpKeepInterval=50&tcpAbortiveClose=true&localSocketAddress=localSocketAddress&socketTimeout=1000&useReadAheadInput=false&tlsSocketType=TLStype&sslMode=TRUST&serverSslCert=mycertPath&keyStore=/tmp&keyStorePassword=MyPWD&keyStoreType=JKS&enabledSslCipherSuites=myCipher,cipher2&enabledSslProtocolSuites=TLSv1.2&allowMultiQueries=true&allowLocalInfile=true&useCompression=true&useAffectedRows=true&useBulkStmts=false&cachePrepStmts=false&prepStmtCacheSize=2&useServerPrepStmts=true&credentialType=ENV&sessionVariables=blabla&connectionAttributes=bla=bla&servicePrincipalName=SPN&blankTableNameMeta=true&tinyInt1isBit=false&yearIsDateType=false&dumpQueriesOnException=true&includeInnodbStatusInDeadlockExceptions=true&includeThreadDumpInDeadlockExceptions=true&retriesAllDown=10&galeraAllowedState=A,B&transactionReplay=true&pool=true&poolName=myPool&maxPoolSize=16&minPoolSize=12&maxIdleTime=25000&registerJmxPool=false&poolValidMinDelay=260&useResetConnection=true&serverRsaPublicKeyFile=RSAPath&allowPublicKeyRetrieval=true",
818818
conf.toString());
819819
}
820820

0 commit comments

Comments
 (0)