Skip to content

Commit

Permalink
[CONJ-1091] Ensure setting connectTimeout as timeout for socket timeo…
Browse files Browse the repository at this point in the history
…ut until connection is done. This permit to set a connectTimeout, while socketTimeout can still be set to 0
  • Loading branch information
rusher committed Jul 25, 2023
1 parent bde0be7 commit 09d19b6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
Expand Up @@ -221,9 +221,12 @@ private static Socket createSocket(final String host, final int port, final Opti
socket = Utils.createSocket(options, host);
socket.setTcpNoDelay(options.tcpNoDelay);

if (options.socketTimeout != null) {
if (options.connectTimeout > 0) {
socket.setSoTimeout(options.connectTimeout);
} else if (options.socketTimeout != null && options.socketTimeout > 0) {
socket.setSoTimeout(options.socketTimeout);
}

if (options.tcpKeepAlive) {
socket.setKeepAlive(true);
}
Expand Down Expand Up @@ -600,9 +603,6 @@ private void createConnection(HostAddress hostAddress, String username) throws S
this.reader.setServerThreadId(this.serverThreadId, isMasterConnection());
this.writer.setServerThreadId(this.serverThreadId, isMasterConnection());

if (this.options.socketTimeout != null) {
this.socketTimeout = this.options.socketTimeout;
}
if ((serverCapabilities & MariaDbServerCapabilities.CLIENT_DEPRECATE_EOF) != 0) {
eofDeprecated = true;
}
Expand Down Expand Up @@ -871,11 +871,8 @@ private void galeraStateValidation() throws SQLException {

private void postConnectionQueries() throws SQLException {
try {

if (options.usePipelineAuth
&& (options.socketTimeout == null
|| options.socketTimeout == 0
|| options.socketTimeout > 500)) {
Integer timeout = options.connectTimeout > 0 ? options.connectTimeout : options.socketTimeout;
if (options.usePipelineAuth && (timeout == null || timeout == 0 || timeout > 500)) {
// set a timeout to avoid hang in case server doesn't support pipelining
socket.setSoTimeout(500);
}
Expand Down Expand Up @@ -922,14 +919,8 @@ private void postConnectionQueries() throws SQLException {
activeStreamingResult = null;
hostFailed = false;

if (options.usePipelineAuth) {
// reset timeout to configured value
if (options.socketTimeout != null) {
socket.setSoTimeout(options.socketTimeout);
} else {
socket.setSoTimeout(0);
}
}
this.socketTimeout = options.socketTimeout == null ? 0 : options.socketTimeout;
socket.setSoTimeout(this.socketTimeout);

} catch (SocketTimeoutException timeoutException) {
destroySocket();
Expand Down
Expand Up @@ -21,6 +21,7 @@ public void nativePassword() throws Exception {
// eat
}
System.out.println("user name:" + System.getProperty("user.name"));
stmt.execute("DROP USER IF EXISTS " + System.getProperty("user.name"));
stmt.execute("CREATE USER " + System.getProperty("user.name") + " IDENTIFIED VIA gssapi");
stmt.execute("GRANT ALL PRIVILEGES ON *.* TO " + System.getProperty("user.name"));

Expand Down

0 comments on commit 09d19b6

Please sign in to comment.