Skip to content
Merged
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
3 changes: 2 additions & 1 deletion packages/snaps-controllers/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Removed

- **RREAKING:** Remove `AbstractExecutionService` class in favour of `ExecutionService` ([#3916](https://github.com/MetaMask/snaps/pull/3916))
- **BREAKING:** Remove `incrementActiveReferences` and `decrementActiveReferences` actions ([#3907](https://github.com/MetaMask/snaps/pull/3907))
- **BREAKING:** Remove `incrementActiveReferences` and `decrementActiveReferences` actions and methods ([#3907](https://github.com/MetaMask/snaps/pull/3907), [#3920](https://github.com/MetaMask/snaps/pull/3920))
- This was never used in production.

## [18.0.4]

Expand Down
61 changes: 0 additions & 61 deletions packages/snaps-controllers/src/snaps/SnapController.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2063,67 +2063,6 @@ describe('SnapController', () => {
await service.terminateAllSnaps();
});

it('does not kill snaps with open sessions', async () => {
const sourceCode = `
module.exports.onRpcRequest = () => 'foo bar';
`;

const rootMessenger = getRootMessenger();

const options = getSnapControllerOptions({
rootMessenger,
idleTimeCheckInterval: 10,
maxIdleTime: 50,
state: {
snaps: getPersistedSnapsState(
getPersistedSnapObject({
manifest: getSnapManifest({
shasum: await getSnapChecksum(getMockSnapFiles({ sourceCode })),
}),
sourceCode,
}),
),
},
});
const [snapController, service] = await getSnapControllerWithEES(options);

const snap = snapController.getSnapExpect(MOCK_SNAP_ID);

await snapController.startSnap(snap.id);
expect(snapController.state.snaps[snap.id].status).toBe('running');

snapController.incrementActiveReferences(snap.id);

expect(
await snapController.handleRequest({
snapId: snap.id,
origin: MOCK_ORIGIN,
handler: HandlerType.OnRpcRequest,
request: {
jsonrpc: '2.0',
method: 'test',
params: {},
id: 1,
},
}),
).toBe('foo bar');

await sleep(100);

// Should still be running after idle timeout
expect(snapController.state.snaps[snap.id].status).toBe('running');

snapController.decrementActiveReferences(snap.id);

await sleep(100);

// Should be terminated by idle timeout now
expect(snapController.state.snaps[snap.id].status).toBe('stopped');

snapController.destroy();
await service.terminateAllSnaps();
});

it(`shouldn't time out a long running snap on start up`, async () => {
const rootMessenger = getRootMessenger();

Expand Down
31 changes: 0 additions & 31 deletions packages/snaps-controllers/src/snaps/SnapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,6 @@ export type SnapRuntimeData = {
*/
lastRequest: null | number;

/**
* The current number of active references where this Snap is being used
*/
activeReferences: number;

/**
* The current pending inbound requests, meaning requests that are processed by snaps.
*/
Expand Down Expand Up @@ -1675,7 +1670,6 @@ export class SnapController extends BaseController<
entries
.filter(
([_snapId, runtime]) =>
runtime.activeReferences === 0 &&
runtime.pendingInboundRequests.length === 0 &&
runtime.lastRequest &&
this.#maxIdleTime &&
Expand Down Expand Up @@ -2569,30 +2563,6 @@ export class SnapController extends BaseController<
}
}

/**
* Handles incrementing the activeReferences counter.
*
* @param snapId - The snap id of the snap that was referenced.
*/
incrementActiveReferences(snapId: SnapId) {
const runtime = this.#getRuntimeExpect(snapId);
runtime.activeReferences += 1;
}

/**
* Handles decrement the activeReferences counter.
*
* @param snapId - The snap id of the snap that was referenced..
*/
decrementActiveReferences(snapId: SnapId) {
const runtime = this.#getRuntimeExpect(snapId);
assert(
runtime.activeReferences > 0,
'SnapController reference management is in an invalid state.',
);
runtime.activeReferences -= 1;
}

/**
* Gets all snaps in their truncated format.
*
Expand Down Expand Up @@ -4324,7 +4294,6 @@ export class SnapController extends BaseController<
installPromise: null,
encryptionKey: null,
encryptionSalt: null,
activeReferences: 0,
pendingInboundRequests: [],
pendingOutboundRequests: 0,
interpreter,
Expand Down
Loading