Skip to content

Commit

Permalink
Merge pull request #324 from v-suhame/getLocalHostName_unix
Browse files Browse the repository at this point in the history
Get local host name before opening TDSChannel
  • Loading branch information
Suraiya Hameed authored Jun 12, 2017
2 parents 9d660f4 + 903864a commit 1da02b5
Showing 1 changed file with 11 additions and 6 deletions.
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

0 comments on commit 1da02b5

Please sign in to comment.