Skip to content

Commit

Permalink
fix: Include request in initial subscribe to gRPC endpoint to fix LB …
Browse files Browse the repository at this point in the history
…connection delay (#252)

* send request with subscribe

* remove unused import

(cherry picked from commit 4239bb7)
  • Loading branch information
vovkman authored and fanatid committed Dec 7, 2023
1 parent 085ed58 commit 6fcbcef
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
6 changes: 1 addition & 5 deletions examples/rust/src/bin/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,7 @@ async fn geyser_subscribe(
request: SubscribeRequest,
resub: usize,
) -> anyhow::Result<()> {
let (mut subscribe_tx, mut stream) = client.subscribe().await?;
subscribe_tx
.send(request)
.await
.map_err(GeyserGrpcClientError::SubscribeSendError)?;
let (mut subscribe_tx, mut stream) = client.subscribe_with_request(Some(request)).await?;

info!("stream opened");
let mut counter = 0;
Expand Down
18 changes: 17 additions & 1 deletion yellowstone-grpc-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,23 @@ impl<F: Interceptor> GeyserGrpcClient<F> {
impl Sink<SubscribeRequest, Error = mpsc::SendError>,
impl Stream<Item = Result<SubscribeUpdate, Status>>,
)> {
let (subscribe_tx, subscribe_rx) = mpsc::unbounded();
self.subscribe_with_request(None).await
}

pub async fn subscribe_with_request(
&mut self,
request: Option<SubscribeRequest>,
) -> GeyserGrpcClientResult<(
impl Sink<SubscribeRequest, Error = mpsc::SendError>,
impl Stream<Item = Result<SubscribeUpdate, Status>>,
)> {
let (mut subscribe_tx, subscribe_rx) = mpsc::unbounded();
if let Some(request) = request {
subscribe_tx
.send(request)
.await
.map_err(GeyserGrpcClientError::SubscribeSendError)?;
}
let response: Response<Streaming<SubscribeUpdate>> =
self.geyser.subscribe(subscribe_rx).await?;
Ok((subscribe_tx, response.into_inner()))
Expand Down

0 comments on commit 6fcbcef

Please sign in to comment.