@@ -1002,9 +1002,10 @@ pub async fn grpc_channel_builder(
10021002 endpoint : String ,
10031003 our_tls : & Option < TlsConfig > ,
10041004 target_tls : & Option < TlsConfig > ,
1005+ connect_timeout : Option < Duration > ,
10051006) -> Result < Endpoint > {
10061007 let config = config ( ) ;
1007- if let Some ( target_tls) = config. get_tls_config ( target_tls) {
1008+ let endpoint = if let Some ( target_tls) = config. get_tls_config ( target_tls) {
10081009 let mut endpoint = Url :: parse ( & endpoint) ?;
10091010 endpoint
10101011 . set_scheme ( "https" )
@@ -1031,11 +1032,17 @@ pub async fn grpc_channel_builder(
10311032 config_builder = config_builder. identity ( Identity :: from_pem ( our_tls. cert , our_tls. key ) ) ;
10321033 }
10331034
1034- Ok ( b. tls_config ( config_builder) . context ( "configuring TLS" ) ?)
1035+ b. tls_config ( config_builder) . context ( "configuring TLS" ) ?
10351036 } else {
10361037 debug ! ( "connecting to grpc endpoint {endpoint}" ) ;
1037- Ok ( Channel :: from_shared ( endpoint. to_string ( ) ) ?)
1038- }
1038+ Channel :: from_shared ( endpoint. to_string ( ) ) ?
1039+ } ;
1040+
1041+ Ok ( if let Some ( connect_timeout) = connect_timeout {
1042+ endpoint. connect_timeout ( connect_timeout)
1043+ } else {
1044+ endpoint
1045+ } )
10391046}
10401047
10411048/// Connect to a gRPC service with optional TLS
@@ -1044,17 +1051,20 @@ pub async fn connect_grpc(
10441051 endpoint : String ,
10451052 our_tls : & Option < TlsConfig > ,
10461053 tls : & Option < TlsConfig > ,
1054+ connect_timeout : Option < Duration > ,
10471055) -> Result < Channel > {
1048- Ok ( grpc_channel_builder ( our_name, endpoint, our_tls, tls)
1049- . await ?
1050- . connect ( )
1051- . await ?)
1056+ Ok (
1057+ grpc_channel_builder ( our_name, endpoint, our_tls, tls, connect_timeout)
1058+ . await ?
1059+ . connect ( )
1060+ . await ?,
1061+ )
10521062}
10531063
10541064/// Connect a raw gRPC channel to the controller endpoint.
10551065pub async fn connect_controller ( our_name : & str , our_tls : & Option < TlsConfig > ) -> Result < Channel > {
10561066 let endpoint = config ( ) . controller_endpoint ( ) ;
1057- connect_grpc ( our_name, endpoint, our_tls, & config ( ) . controller . tls ) . await
1067+ connect_grpc ( our_name, endpoint, our_tls, & config ( ) . controller . tls , None ) . await
10581068}
10591069
10601070pub async fn controller_client (
@@ -1077,7 +1087,7 @@ pub async fn job_controller_client(
10771087 & config ( ) . controller . tls
10781088 } ;
10791089
1080- let channel = connect_grpc ( our_name, addr, our_tls, their_tls) . await ?;
1090+ let channel = connect_grpc ( our_name, addr, our_tls, their_tls, None ) . await ?;
10811091 Ok ( job_controller_grpc_client:: JobControllerGrpcClient :: new (
10821092 channel,
10831093 ) )
@@ -1088,9 +1098,17 @@ pub async fn job_status_client(
10881098 our_tls : & Option < TlsConfig > ,
10891099 worker_id : WorkerId ,
10901100 addr : String ,
1101+ connect_timeout : Option < Duration > ,
10911102) -> Result < job_status_grpc_client:: JobStatusGrpcClient < InterceptedService < Channel , InjectWorkerId > > >
10921103{
1093- let channel = connect_grpc ( our_name, addr, our_tls, & config ( ) . worker . tls ) . await ?;
1104+ let channel = connect_grpc (
1105+ our_name,
1106+ addr,
1107+ our_tls,
1108+ & config ( ) . worker . tls ,
1109+ connect_timeout,
1110+ )
1111+ . await ?;
10941112 Ok (
10951113 job_status_grpc_client:: JobStatusGrpcClient :: with_interceptor (
10961114 channel,
0 commit comments