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

Get local host name before opening TDSChannel #324

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
import java.util.Map;
import java.util.Properties;
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level;

import javax.sql.XAConnection;
Expand Down Expand Up @@ -223,6 +223,8 @@ ServerPortPlaceHolder getRoutingInfo() {
// is
// false).

private static String hostName = null;

boolean sendStringParametersAsUnicode() {
return sendStringParametersAsUnicode;
}
Expand Down Expand Up @@ -1991,6 +1993,14 @@ private void connectHelper(ServerPortPlaceHolder serverInfo,
connectionlogger.fine(toString() + " Connecting with server: " + serverInfo.getServerName() + " port: " + serverInfo.getPortNumber()
+ " Timeout slice: " + timeOutsliceInMillis + " Timeout Full: " + timeOutFullInSeconds);
}

// Before opening the TDSChannel, calculate local hostname
// as the InetAddress.getLocalHost() takes more than usual time in certain OS and JVM combination, it avoids connection loss
hostName = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.WORKSTATION_ID.toString());
if (StringUtils.isEmpty(hostName)) {
hostName = Util.lookupHostName();
}

// if the timeout is infinite slices are infinite too.
tdsChannel = new TDSChannel(this);
if (0 == timeOutFullInSeconds)
Expand Down Expand Up @@ -4015,7 +4025,6 @@ final boolean complete(LogonCommand logonCommand,
// Fed Auth feature requested without specifying fedAuthFeatureExtensionData.
assert (null != fedAuthFeatureExtensionData || !(federatedAuthenticationInfoRequested || federatedAuthenticationRequested));

String hostName = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.WORKSTATION_ID.toString());
String sUser = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.USER.toString());
String sPwd = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.PASSWORD.toString());
String appName = activeConnectionProperties.getProperty(SQLServerDriverStringProperty.APPLICATION_NAME.toString());
Expand All @@ -4034,10 +4043,6 @@ final boolean complete(LogonCommand logonCommand,
if (serverName != null && serverName.length() > 128)
serverName = serverName.substring(0, 128);

if (hostName == null || hostName.length() == 0) {
hostName = Util.lookupHostName();
}

byte[] secBlob = new byte[0];
boolean[] done = {false};
if (null != authentication) {
Expand Down