@@ -51,7 +51,7 @@ public void open(HostAddress address, int timeout, SSLParam sslParam)
5151 try {
5252
5353 this .serverAddr = address ;
54- this .timeout = timeout <= 0 ? Integer .MAX_VALUE : timeout ;
54+ this .timeout = timeout <= 0 ? Integer .MAX_VALUE : timeout ;
5555 this .enabledSsl = true ;
5656 this .sslParam = sslParam ;
5757 if (sslSocketFactory == null ) {
@@ -78,6 +78,7 @@ public void open(HostAddress address, int timeout, SSLParam sslParam)
7878 Charsets .UTF_8 ));
7979 }
8080 } catch (TException | IOException e ) {
81+ close ();
8182 throw new IOErrorException (IOErrorException .E_UNKNOWN , e .getMessage ());
8283 }
8384 }
@@ -87,7 +88,7 @@ public void open(HostAddress address, int timeout)
8788 throws IOErrorException , ClientServerIncompatibleException {
8889 try {
8990 this .serverAddr = address ;
90- this .timeout = timeout <= 0 ? Integer .MAX_VALUE : timeout ;
91+ this .timeout = timeout <= 0 ? Integer .MAX_VALUE : timeout ;
9192 this .transport = new TSocket (
9293 address .getHost (), address .getPort (), this .timeout , this .timeout );
9394 this .transport .open ();
@@ -136,18 +137,18 @@ public AuthResult authenticate(String user, String password)
136137 throw new AuthFailedException (new String (resp .error_msg ));
137138 } else {
138139 throw new AuthFailedException (
139- "The error_msg is null, "
140- + "maybe the service not set or the response is disorder." );
140+ "The error_msg is null, "
141+ + "maybe the service not set or the response is disorder." );
141142 }
142143 }
143144 return new AuthResult (resp .getSession_id (), resp .getTime_zone_offset_seconds ());
144145 } catch (TException e ) {
145146 if (e instanceof TTransportException ) {
146- TTransportException te = (TTransportException )e ;
147+ TTransportException te = (TTransportException ) e ;
147148 if (te .getType () == TTransportException .END_OF_FILE ) {
148149 throw new IOErrorException (IOErrorException .E_CONNECT_BROKEN , te .getMessage ());
149150 } else if (te .getType () == TTransportException .TIMED_OUT
150- || te .getMessage ().contains ("Read timed out" )) {
151+ || te .getMessage ().contains ("Read timed out" )) {
151152 reopen ();
152153 throw new IOErrorException (IOErrorException .E_TIME_OUT , te .getMessage ());
153154 } else if (te .getType () == TTransportException .NOT_OPEN ) {
@@ -170,7 +171,7 @@ public ExecutionResponse execute(long sessionID, String stmt)
170171 } else if (te .getType () == TTransportException .NOT_OPEN ) {
171172 throw new IOErrorException (IOErrorException .E_NO_OPEN , te .getMessage ());
172173 } else if (te .getType () == TTransportException .TIMED_OUT
173- || te .getMessage ().contains ("Read timed out" )) {
174+ || te .getMessage ().contains ("Read timed out" )) {
174175 try {
175176 reopen ();
176177 } catch (ClientServerIncompatibleException ex ) {
@@ -224,7 +225,7 @@ public boolean ping() {
224225 }
225226
226227 public void close () {
227- if (transport != null ) {
228+ if (transport != null && transport . isOpen () ) {
228229 transport .close ();
229230 }
230231 }
0 commit comments