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(connection): gracefully handle missing method #2351

Merged
merged 4 commits into from
Jun 5, 2017

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented May 24, 2017

fixes #2321

also observed errors in devtools when we get command callbacks for commands LH didn't send

Copy link
Collaborator

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

LGTM! Just a bit unsure about the ????? method name when it's unknown.

@patrickhulce
Copy link
Collaborator Author

Just a bit unsure about the ????? method name when it's unknown.

Yeah using unknown just blended in a bit too much with the rest of the logs and this makes it a little clearer something weird is going on, open to suggestions though :)

@brendankenny
Copy link
Member

did anyone have any more insight into the cause of this? We don't want to crash in the faces of this, but without error tracking this will start to get lost with this change. The devtools case is more understandable, but feedback commands we didn't send is something we should probably track down

@patrickhulce
Copy link
Collaborator Author

did anyone have any more insight into the cause of this?

Nope :) it seems impossible from the stack trace in the issue since if it fails in the resolve it should have definitely failed the first time when it was sending the message (because it actually gets the method when the callback was set)

but without error tracking this will start to get lost with this change

Good thing we're approved for sentry now let's get it installed post-branch :D

@@ -92,7 +92,7 @@ class Connection {
const object = JSON.parse(message);
// Remote debugging protocol is JSON RPC 2.0 compiant. In terms of that transport,
// responses to the commands carry "id" property, while notifications do not.
if (object.id) {
if (this._callbacks.has(object.id)) {
Copy link
Member

Choose a reason for hiding this comment

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

what do you think about making this more explicit than treating it like an event if no callback (it's not really an event since the message does have an id)? Could do a third case with a call to formatProtocol with an explicit ????? (and no emit).

Also with level error so it hits log.error? Not sure about that one if this is a regular occurrence in devtools land

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure

@brendankenny
Copy link
Member

Good thing we're approved for sentry now let's get it installed post-branch :D

file an issue in that case? We don't want to forget that we're silencing this

@patrickhulce
Copy link
Collaborator Author

@brendankenny filed #2364

@@ -106,11 +106,15 @@ class Connection {
{method: callback.method, params: object.result}, 'verbose');
return object.result;
}));
} else if (object.id) {
const error = object.error && object.error.message;
Copy link
Member

Choose a reason for hiding this comment

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

add a comment about why this might happen (pavel's old "while notifications do not" comment above probably should also be updated as it implies only two states)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

} else if (object.id) {
const error = object.error && object.error.message;
log.formatProtocol(`disowned method <= browser ${error ? 'ERR' : 'OK'}`,
{method: object.method, params: error || object.result}, 'verbose');
Copy link
Member

Choose a reason for hiding this comment

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

normalize object.method here rather than in formatProtocol?

Copy link
Member

Choose a reason for hiding this comment

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

if it's an error, params probably shouldn't be set to the message?

Copy link
Member

Choose a reason for hiding this comment

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

and should it still throw if there's an error?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

normalize object.method here rather than in formatProtocol?

I'd really rather not, that's exactly what got us into this mess of fatally erroring on unexpected input, unless I'm misunderstanding what you mean by "normalize" haha

if it's an error, params probably shouldn't be set to the message?

where would you like to log the message then?

and should it still throw if there's an error?

that would make these fatal in the future which seems bad. the point is that we don't care about these "disowned" (better name pending you 😄 ) events

Copy link
Member

Choose a reason for hiding this comment

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

normalize object.method here rather than in formatProtocol?

I'd really rather not, that's exactly what got us into this mess of fatally erroring on unexpected input, unless I'm misunderstanding what you mean by "normalize"

I mean const method = object.method || '?????'; here instead of in formatProtocol just for the logging, not for how it's handled.

where would you like to log the message then?

For better or worse, formatProtocol expects a data.method and data.params, so it's better to be strict in sending that than to just let it support whatever. formatProtocol's existence now is kind of dumb (all it's really doing beyond log.verbose is clipping to the end of the line), but rather than eliminating, maybe we can just quickly revise the parameters rather than overload them?

that would make these fatal in the future which seems bad

yeah, makes sense.

@@ -106,11 +106,15 @@ class Connection {
{method: callback.method, params: object.result}, 'verbose');
return object.result;
}));
} else if (object.id) {
const error = object.error && object.error.message;
log.formatProtocol(`disowned method <= browser ${error ? 'ERR' : 'OK'}`,
Copy link
Member

Choose a reason for hiding this comment

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

disowned may not be a good word here (sounds like LH did send the command but doesn't care about it now :), but not sure of a good replacement.

Copy link
Member

Choose a reason for hiding this comment

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

nonrequested?

@paulirish paulirish merged commit 89798d1 into master Jun 5, 2017
@paulirish paulirish deleted the graceful_missing_method branch June 5, 2017 17:06
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.

Lighthouse 2.0.0 crash
4 participants