@@ -184,17 +184,28 @@ public void start(ClientCall.Listener<RespT> responseListener, Metadata headers)
184184 }
185185
186186 assert channel != null ;
187- blockingStub = MilvusServiceGrpc .newBlockingStub (channel );
188- futureStub = MilvusServiceGrpc .newFutureStub (channel );
189-
190- // calls a RPC Connect() to the remote server, and sends the client info to the server
191- // so that the server knows which client is interacting, especially for accesses log.
192- this .timeoutMs = connectParam .getConnectTimeoutMs (); // set this value to connectTimeoutMs to control the retry()
193- R <ConnectResponse > resp = this .retry (() -> connect (connectParam ));
194- if (resp .getStatus () != R .Status .Success .getCode ()) {
195- String msg = "Failed to initialize connection. Error: " + resp .getMessage ();
196- logError (msg );
197- throw new RuntimeException (msg );
187+
188+ try {
189+ blockingStub = MilvusServiceGrpc .newBlockingStub (channel );
190+ futureStub = MilvusServiceGrpc .newFutureStub (channel );
191+
192+ // calls a RPC Connect() to the remote server, and sends the client info to the server
193+ // so that the server knows which client is interacting, especially for accesses log.
194+ this .timeoutMs = connectParam .getConnectTimeoutMs (); // set this value to connectTimeoutMs to control the retry()
195+ R <ConnectResponse > resp = this .retry (() -> connect (connectParam ));
196+ if (resp .getStatus () != R .Status .Success .getCode ()) {
197+ String msg = "Failed to initialize connection. Error: " + resp .getMessage ();
198+ logError (msg );
199+ throw new RuntimeException (msg );
200+ }
201+ } catch (Exception e ) {
202+ // close the channel if connect() throws exception, avoid leakage
203+ try {
204+ close (3 );
205+ } catch (InterruptedException ignored ) {
206+ Thread .currentThread ().interrupt ();
207+ }
208+ throw e ;
198209 }
199210 this .timeoutMs = 0 ; // reset the timeout value to default
200211 }
0 commit comments