From ae3ba752b93b1d304cd9dc1a925b6236d28ae59b Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 25 Mar 2026 12:01:05 +0100 Subject: [PATCH 1/3] Remove active references --- .../src/snaps/SnapController.test.tsx | 61 ------------------- .../src/snaps/SnapController.ts | 31 ---------- 2 files changed, 92 deletions(-) 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, From 7a5ac0fcdf4aae716dba8c6afcc8f243c0947c39 Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 25 Mar 2026 12:03:07 +0100 Subject: [PATCH 2/3] Update changelog --- packages/snaps-controllers/CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/snaps-controllers/CHANGELOG.md b/packages/snaps-controllers/CHANGELOG.md index cc6ae41682..3d41897765 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 `activeReferences` runtime data, `incrementActiveReferences` and `decrementActiveReferences` actions ([#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] From f4474b4284a899be751f71ca655f081db914546b Mon Sep 17 00:00:00 2001 From: Maarten Zuidhoorn Date: Wed, 25 Mar 2026 12:38:14 +0100 Subject: [PATCH 3/3] Update changelog --- packages/snaps-controllers/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/snaps-controllers/CHANGELOG.md b/packages/snaps-controllers/CHANGELOG.md index 3d41897765..e225996250 100644 --- a/packages/snaps-controllers/CHANGELOG.md +++ b/packages/snaps-controllers/CHANGELOG.md @@ -84,7 +84,7 @@ 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 `activeReferences` runtime data, `incrementActiveReferences` and `decrementActiveReferences` actions ([#3907](https://github.com/MetaMask/snaps/pull/3907), [#3920](https://github.com/MetaMask/snaps/pull/3920)) +- **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]