Skip to content
Merged
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 @@ -4,7 +4,7 @@ import ObjectMultiplex from '@metamask/object-multiplex';
import type { BasePostMessageStream } from '@metamask/post-message-stream';
import { JsonRpcError } from '@metamask/rpc-errors';
import type { SnapRpcHookArgs } from '@metamask/snaps-utils';
import { SNAP_STREAM_NAMES, logError } from '@metamask/snaps-utils';
import { SNAP_STREAM_NAMES, logError, logWarning } from '@metamask/snaps-utils';
import type {
Json,
JsonRpcNotification,
Expand Down Expand Up @@ -180,12 +180,7 @@ export abstract class AbstractExecutionService<WorkerType>
);

if (result === hasTimedOut || result !== 'OK') {
// We tried to shutdown gracefully but failed. This probably means the Snap is in infinite loop and
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment accurate? Does a failure to terminate gracefully always (or usually) indicate a bug in the snap? If so, what impact would we expect this to have on users if any?

I ask because we may want to consider forcibly disabling the snap and/or warning the user that it's misbehaving.

Copy link
Member Author

Choose a reason for hiding this comment

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

That was the assumption originally, but I removed it specifically because I didn't think it was accurate anymore.

The Snap gets very limited time to gracefully terminate (1s), so on lower-end systems it seems likelier now that we may see this as a "false-postive" of sorts. Especially since we see this on our own Snaps in production which shouldn't be hogging CPU by running a while-loop.

It may still warrant some investigation into whether we can better guarantee graceful termination and whether there is any issues in our own Snaps that cause this to happen more often.

// hogging down the whole JS process.
// TODO(ritave): It might be doing weird things such as posting a lot of setTimeouts. Add a test to ensure that this behaviour
// doesn't leak into other workers. Especially important in IframeExecutionEnvironment since they all share the same
// JS process.
logError(`Snap "${snapId}" failed to terminate gracefully.`, result);
logWarning(`Snap "${snapId}" failed to terminate gracefully.`);
}
} catch {
// Ignore
Expand Down
Loading