Skip to content

Commit 8c42803

Browse files
catch errors on grpc consumption
1 parent a1b353b commit 8c42803

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

cluster-endpoints/examples/grpc_using_streams.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ pub async fn main() {
3939

4040

4141
// mango validator (mainnet)
42-
let grpc_addr_mainnet_triton = "http://202.8.9.108:10000".to_string();
42+
// let grpc_addr_mainnet_triton = "http://202.8.9.108:10000".to_string();
43+
// via toxiproxy
44+
let grpc_addr_mainnet_triton = "http://127.0.0.1:10001".to_string();
4345
// ams81 (mainnet)
4446
let grpc_addr_mainnet_ams81 = "http://202.8.8.12:10000".to_string();
4547
// testnet - NOTE: this connection has terrible lags (almost 5 minutes)
@@ -74,8 +76,8 @@ async fn create_multiplex(
7476

7577
let jh = tokio::spawn(async move {
7678

77-
let mut green = create_geyser_stream2(grpc_addr_mainnet_triton.clone(), None).await;
78-
let mut blue = create_geyser_stream2(grpc_addr_mainnet_ams81.clone(), None).await;
79+
let mut green = create_geyser_stream2("green-toxiproxy".to_string(), grpc_addr_mainnet_triton.clone(), None).await;
80+
let mut blue = create_geyser_stream2("blue".to_string(), grpc_addr_mainnet_ams81.clone(), None).await;
7981
pin_mut!(green);
8082
pin_mut!(blue);
8183

@@ -186,9 +188,9 @@ async fn create_geyser_stream(grpc_addr: String, x_token: Option<String>) -> imp
186188
return stream;
187189
}
188190

189-
async fn create_geyser_stream2(grpc_addr: String, x_token: Option<String>) -> impl Stream<Item = SubscribeUpdate> {
190-
191+
async fn create_geyser_stream2(label: String, grpc_addr: String, x_token: Option<String>) -> impl Stream<Item = SubscribeUpdate> {
191192

193+
// throws e.g. InvalidUri(InvalidUri(InvalidAuthority))
192194
let mut client = GeyserGrpcClient::connect(grpc_addr, x_token, None).unwrap();
193195

194196
let mut blocks_subs = HashMap::new();
@@ -221,15 +223,19 @@ async fn create_geyser_stream2(grpc_addr: String, x_token: Option<String>) -> im
221223

222224
match update_message {
223225
Ok(update_message) => {
226+
info!(">message on {}", label);
224227
yield update_message;
225228
}
226229
Err(status) => {
227-
error!(">stream: {:?}", status);
230+
error!(">error while receiving from stream {}: {:?}", label, status);
231+
// note: the for loop will terminate after this
228232
}
229233
}
230234

231235
}
232236

237+
warn!("stream consumer loop terminated for {}", label);
238+
233239
}
234240

235241

0 commit comments

Comments
 (0)