diff --git a/packages/snaps-controllers/CHANGELOG.md b/packages/snaps-controllers/CHANGELOG.md index cc6ae41682..e225996250 100644 --- a/packages/snaps-controllers/CHANGELOG.md +++ b/packages/snaps-controllers/CHANGELOG.md @@ -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] diff --git a/packages/snaps-controllers/src/snaps/SnapController.test.tsx b/packages/snaps-controllers/src/snaps/SnapController.test.tsx index e81c630ae1..6899f3e29f 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.test.tsx +++ b/packages/snaps-controllers/src/snaps/SnapController.test.tsx @@ -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(); diff --git a/packages/snaps-controllers/src/snaps/SnapController.ts b/packages/snaps-controllers/src/snaps/SnapController.ts index 2e47e79aad..f67a8cd7f6 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.ts +++ b/packages/snaps-controllers/src/snaps/SnapController.ts @@ -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. */ @@ -1675,7 +1670,6 @@ export class SnapController extends BaseController< entries .filter( ([_snapId, runtime]) => - runtime.activeReferences === 0 && runtime.pendingInboundRequests.length === 0 && runtime.lastRequest && this.#maxIdleTime && @@ -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. * @@ -4324,7 +4294,6 @@ export class SnapController extends BaseController< installPromise: null, encryptionKey: null, encryptionSalt: null, - activeReferences: 0, pendingInboundRequests: [], pendingOutboundRequests: 0, interpreter,