File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,10 @@ impl RpcMultiClient {
73
73
where
74
74
F : Fn ( & ' a RpcClient ) -> Pin < Box < dyn Future < Output = anyhow:: Result < T > > + Send + ' a > > ,
75
75
{
76
+ if self . rpc_clients . is_empty ( ) {
77
+ bail ! ( "No RPC clients available for operation: {}" , operation_name) ;
78
+ }
79
+
76
80
let mut attempts = 0 ;
77
81
// Try all endpoints twice in the worst case.
78
82
let max_attempts = self . rpc_clients . len ( ) * 2 ;
@@ -134,7 +138,8 @@ impl RpcMultiClient {
134
138
let mut found_index = None ;
135
139
for _ in 0 ..state. endpoint_states . len ( ) {
136
140
let index = state. current_index ;
137
- state. current_index = ( state. current_index + 1 ) % state. endpoint_states . len ( ) ;
141
+ state. current_index =
142
+ ( state. current_index + 1 ) . checked_rem ( state. endpoint_states . len ( ) ) ?;
138
143
139
144
// Choose the next endpoint that is either healthy or has waited out the cooldown period.
140
145
#[ allow( clippy:: indexing_slicing, reason = "index is checked" ) ]
@@ -152,7 +157,7 @@ impl RpcMultiClient {
152
157
// If all endpoints have failed, simply move on to the next one.
153
158
if found_index. is_none ( ) {
154
159
let index = start_index;
155
- state. current_index = ( start_index + 1 ) % state. endpoint_states . len ( ) ;
160
+ state. current_index = ( start_index + 1 ) . checked_rem ( state. endpoint_states . len ( ) ) ? ;
156
161
found_index = Some ( index) ;
157
162
}
158
163
found_index
You can’t perform that action at this time.
0 commit comments