File tree 2 files changed +15
-3
lines changed
2 files changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -74,6 +74,8 @@ error_messages! { ConnectionError
74
74
23 : "Invalid URL '{address}': missing port." ,
75
75
AddressTranslationMismatch { unknown: HashSet <Address >, unmapped: HashSet <Address > } =
76
76
24 : "Address translation map does not match the server's advertised address list. User-provided servers not in the advertised list: {unknown:?}. Advertised servers not mapped by user: {unmapped:?}." ,
77
+ ConnectionTimedOut =
78
+ 25 : "Connection to the server timed out."
77
79
}
78
80
79
81
error_messages ! { InternalError
@@ -196,6 +198,8 @@ impl From<Status> for Error {
196
198
Self :: Connection ( ConnectionError :: ServerConnectionFailedStatusError { error : status. message ( ) . to_owned ( ) } )
197
199
} else if status. code ( ) == Code :: Unimplemented {
198
200
Self :: Connection ( ConnectionError :: RPCMethodUnavailable { message : status. message ( ) . to_owned ( ) } )
201
+ } else if status. code ( ) == Code :: Cancelled && status. message ( ) == "Timeout expired" {
202
+ Self :: Connection ( ConnectionError :: ConnectionTimedOut )
199
203
} else {
200
204
Self :: from_message ( status. message ( ) )
201
205
}
Original file line number Diff line number Diff line change 17
17
* under the License.
18
18
*/
19
19
20
- use std:: sync:: { Arc , RwLock } ;
20
+ use std:: {
21
+ sync:: { Arc , RwLock } ,
22
+ time:: Duration ,
23
+ } ;
21
24
22
25
use tonic:: {
23
26
body:: BoxBody ,
@@ -49,8 +52,13 @@ impl GRPCChannel for PlainTextChannel {}
49
52
50
53
impl GRPCChannel for CallCredChannel { }
51
54
55
+ const TIMEOUT : Duration = Duration :: from_secs ( 60 ) ;
56
+
52
57
pub ( super ) fn open_plaintext_channel ( address : Address ) -> PlainTextChannel {
53
- PlainTextChannel :: new ( Channel :: builder ( address. into_uri ( ) ) . connect_lazy ( ) , PlainTextFacade )
58
+ PlainTextChannel :: new (
59
+ Channel :: builder ( address. into_uri ( ) ) . timeout ( TIMEOUT ) . connect_lazy ( ) ,
60
+ PlainTextFacade ,
61
+ )
54
62
}
55
63
56
64
#[ derive( Clone , Debug ) ]
@@ -66,7 +74,7 @@ pub(super) fn open_callcred_channel(
66
74
address : Address ,
67
75
credential : Credential ,
68
76
) -> Result < ( CallCredChannel , Arc < CallCredentials > ) > {
69
- let mut builder = Channel :: builder ( address. into_uri ( ) ) ;
77
+ let mut builder = Channel :: builder ( address. into_uri ( ) ) . timeout ( TIMEOUT ) ;
70
78
if credential. is_tls_enabled ( ) {
71
79
builder = builder. tls_config ( credential. tls_config ( ) . clone ( ) . unwrap ( ) ) ?;
72
80
}
You can’t perform that action at this time.
0 commit comments