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

Ignore unknown events in the client, at deserialization. #9471

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,16 @@ where
let raw = BASE64
.decode(event.data.as_bytes())
.map_err(|_| ConnectionError::BadContent)?;
let cooked =
T::api_load_response(raw.as_ref()).map_err(|_| ConnectionError::BadContent)?;
SSEResponseOrMissedEvents::Response(cooked)
match T::api_load_response(raw.as_ref()) {
Ok(cooked) => SSEResponseOrMissedEvents::Response(cooked),
Err(e) => {
log::trace!("Invalid event data: {e}");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use a log::warn!() since it's a useful information to know?

// we ignore bad deserialization
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain in this comment that ignoring a bad deserialization error is useful to not break compatibility when new event types are added to our protocol?

Also comments should start with a capitalized letter.

SSEResponseOrMissedEvents::Empty
}
}
}

// Unknown event should still be returned given it can modify `retry` param
_ => SSEResponseOrMissedEvents::Empty,
};
Expand Down
18 changes: 17 additions & 1 deletion libparsec/crates/client_connection/tests/unit/authenticated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,14 @@ async fn sse_event_id_mocked(
#[cfg(not(target_arch = "wasm32"))]
#[parsec_test(testbed = "minimal")]
async fn sse_retry_mocked(
#[values("good", "good_with_data", "empty", "not_a_number")] kind: &'static str,
#[values(
"good",
"good_with_data",
"empty",
"not_a_number",
"bad_deserialization"
)]
kind: &'static str,
env: &TestbedEnv,
) {
let alice = env.local_device("alice@dev1");
Expand Down Expand Up @@ -548,6 +555,11 @@ async fn sse_retry_mocked(
),
"empty" => register_send_hook!("retry: \ndata:\n\n"),
"not_a_number" => register_send_hook!("retry: <dummy>\ndata:\n\n"),
// "bad_deserialization" in base46
"bad_deserialization" => {
// cspell:disable-next-line
register_send_hook!("data: YmFkX2Rlc2VyaWFsaXphdGlvbg==\nretry: 1000\n\n")
}
unknown => unreachable!("{}", unknown),
}

Expand Down Expand Up @@ -578,6 +590,10 @@ async fn sse_retry_mocked(
p_assert_matches!(event.message, SSEResponseOrMissedEvents::Empty);
p_assert_eq!(event.retry, None);
}
"bad_deserialization" => {
p_assert_matches!(event.message, SSEResponseOrMissedEvents::Empty);
p_assert_eq!(event.retry, Some(std::time::Duration::from_millis(1000)));
}
unknown => unreachable!("{}", unknown),
}
}
Expand Down
Loading