Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(client): close subscription when server sent SubscriptionClosed notification #721

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 11 additions & 1 deletion core/src/client/async_client/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use std::time::Duration;

use crate::client::async_client::manager::{RequestManager, RequestStatus};
use crate::client::{RequestMessage, TransportSenderT};
use crate::error::SubscriptionClosed;
use crate::Error;

use futures_channel::{mpsc, oneshot};
Expand Down Expand Up @@ -84,7 +85,16 @@ pub(crate) fn process_subscription_response(
};

match manager.as_subscription_mut(&request_id) {
Some(send_back_sink) => match send_back_sink.try_send(response.params.result) {
Some(send_back_sink) => match send_back_sink.try_send(response.params.result.clone()) {
// The server sent a subscription closed notification, then close down the subscription.
Ok(()) if serde_json::from_value::<SubscriptionClosed>(response.params.result).is_ok() => {
if manager.remove_subscription(request_id, sub_id.clone()).is_some() {
Ok(())
} else {
tracing::error!("The server tried to closed down invalid subscription: {:?}", sub_id);
niklasad1 marked this conversation as resolved.
Show resolved Hide resolved
Err(None)
}
}
Ok(()) => Ok(()),
Err(err) => {
tracing::error!("Dropping subscription {:?} error: {:?}", sub_id, err);
Expand Down
1 change: 1 addition & 0 deletions tests/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ async fn ws_server_cancels_sub_stream_after_err() {
let exp = SubscriptionClosed::new(SubscriptionClosedReason::Server(err.to_string()));
// The server closed down the subscription with the underlying error from the stream.
assert!(matches!(sub.next().await, Some(Err(Error::SubscriptionClosed(close_reason))) if close_reason == exp));
assert!(sub.next().await.is_none());
}

#[tokio::test]
Expand Down