Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure socketTimeout is < loginTimeout before connected #2280

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,13 @@ final InetSocketAddress open(String host, int port, int timeoutMillis, boolean u
tcpSocket.setKeepAlive(true);
setSocketOptions(tcpSocket, this);

// set SO_TIMEOUT
int socketTimeout = con.getSocketTimeoutMilliseconds();

// socket timeout should be bounded by loginTimeout before connected
if (!con.isConnected()) {
socketTimeout = Math.min(con.timerRemaining(con.timerExpire), socketTimeout);
}

tcpSocket.setSoTimeout(socketTimeout);

inputStream = tcpInputStream = new ProxyInputStream(tcpSocket.getInputStream());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,8 @@ public void setIgnoreOffsetOnDateTimeOffsetConversion(boolean ignoreOffsetOnDate
this.ignoreOffsetOnDateTimeOffsetConversion = ignoreOffsetOnDateTimeOffsetConversion;
}

private boolean calcBigDecimalPrecision = SQLServerDriverBooleanProperty.CALC_BIG_DECIMAL_PRECISION.getDefaultValue();
private boolean calcBigDecimalPrecision = SQLServerDriverBooleanProperty.CALC_BIG_DECIMAL_PRECISION
.getDefaultValue();

@Override
public boolean getCalcBigDecimalPrecision() {
Expand Down Expand Up @@ -1689,7 +1690,7 @@ final int getRetryCount() {
return connectRetryCount;
}

final boolean attachConnId() {
final boolean isConnected() {
return state.equals(State.CONNECTED);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ static String generateStateCode(SQLServerConnection con, int errNum, Integer dat
* original error string.
*/
static String checkAndAppendClientConnId(String errMsg, SQLServerConnection conn) {
if (null != conn && conn.attachConnId()) {
if (null != conn && conn.isConnected()) {
UUID clientConnId = conn.getClientConIdInternal();
assert null != clientConnId;
StringBuilder sb = new StringBuilder(errMsg);
Expand Down
Loading