@@ -110,18 +110,28 @@ Socket connect(ConnectionConfig config, long timeoutMs) throws IOException {
110
110
DefaultConnectionInfoCache instance = getConnection (config );
111
111
try {
112
112
113
- SSLSocket socket = instance .createSslSocket (timeoutMs );
113
+ String instanceIp = instance .getConnectionMetadata (timeoutMs ).getPreferredIpAddress ();
114
+ logger .debug (String .format ("[%s] Connecting to instance." , instanceIp ));
114
115
116
+ SSLSocket socket = instance .createSslSocket (timeoutMs );
115
117
socket .setKeepAlive (true );
116
118
socket .setTcpNoDelay (true );
119
+ socket .connect (new InetSocketAddress (instanceIp , serverProxyPort ));
117
120
118
- String instanceIp = instance .getConnectionMetadata (timeoutMs ).getPreferredIpAddress ();
121
+ try {
122
+ socket .startHandshake ();
123
+ } catch (IOException e ) {
124
+ logger .debug ("TLS handshake failed!" );
125
+ throw e ;
126
+ }
119
127
120
- socket .connect (new InetSocketAddress (instanceIp , serverProxyPort ));
121
- socket .startHandshake ();
128
+ logger .debug (String .format ("[%s] Connected to instance successfully." , instanceIp ));
122
129
123
130
return socket ;
124
131
} catch (IOException e ) {
132
+ logger .debug (
133
+ String .format (
134
+ "[%s] Socket connection failed! Trigger a refresh." , config .getCloudSqlInstance ()));
125
135
instance .forceRefresh ();
126
136
throw e ;
127
137
}
@@ -142,11 +152,14 @@ DefaultConnectionInfoCache getConnection(ConnectionConfig config) {
142
152
}
143
153
144
154
private DefaultConnectionInfoCache createConnectionInfo (ConnectionConfig config ) {
155
+ logger .debug (
156
+ String .format ("[%s] Connection info added to cache." , config .getCloudSqlInstance ()));
145
157
return new DefaultConnectionInfoCache (
146
158
config , adminApi , instanceCredentialFactory , executor , localKeyPair , minRefreshDelayMs );
147
159
}
148
160
149
161
public void close () {
162
+ logger .debug ("Close all connections and remove them from cache." );
150
163
this .instances .forEach ((key , c ) -> c .close ());
151
164
this .instances .clear ();
152
165
}
0 commit comments