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

Report response parse errors to avoid freezes #639

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

marmistrz
Copy link
Contributor

@marmistrz marmistrz commented May 27, 2022

This is at least a workaround for the issue reported in #566.

Whether or not we choose to be strict in parsing, we should report the deserialization errors instead of letting the called wait indefinitely.

Comment on lines +269 to +279
fn parse_message(data: &[u8]) -> Option<ParsedMessage> {
if let Ok(notification) = helpers::to_notification_from_slice(data) {
Some(ParsedMessage::Notification(notification))
} else if let Ok(response) = helpers::to_response_from_slice(data) {
Some(ParsedMessage::Response(response))
} else if let Some(id) = helpers::response_id_from_slice(data) {
Some(ParsedMessage::InvalidResponse(id))
} else {
None
}
}
Copy link
Owner

Choose a reason for hiding this comment

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

I guess it might be better to simply use untagged enum ParsedMessage with default serde deserialize behaviour? Given some tests are written I think it should be simpler to reason about and possibly also faster than manually attempting to parse the response couple of times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants