mirror of
https://github.com/hoppscotch/hoppscotch.git
synced 2026-04-25 16:55:59 +03:00
[PR #5800] [MERGED] fix: prevent memory leaks in experimental scripting sandbox #5357
Labels
No labels
CodeDay
a11y
browser limited
bug
bug fix
cli
core
critical
design
desktop
discussion
docker
documentation
duplicate
enterprise
feature
feature
fosshack
future
good first issue
hacktoberfest
help wanted
i18n
invalid
major
minor
need information
need testing
not applicable to hoppscotch
not reproducible
pull-request
question
refactor
resolved
sandbox
self-host
spam
stale
testmu
wip
wont fix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/hoppscotch#5357
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/hoppscotch/hoppscotch/pull/5800
Author: @jamesgeorge007
Created: 1/23/2026
Status: ✅ Merged
Merged: 1/27/2026
Merged by: @jamesgeorge007
Base:
next← Head:fix/sandbox-memory-leaks📝 Commits (1)
b19f85ffix: prevent memory leaks in experimental scripting sandbox📊 Changes
8 files changed (+110 additions, -57 deletions)
View changed files
📝
packages/hoppscotch-common/src/components/MonacoScriptEditor.vue(+2 -0)📝
packages/hoppscotch-common/src/services/inspection/index.ts(+72 -46)📝
packages/hoppscotch-common/src/services/inspection/inspectors/environment.inspector.ts(+2 -3)📝
packages/hoppscotch-js-sandbox/src/node/pre-request/experimental.ts(+2 -2)📝
packages/hoppscotch-js-sandbox/src/node/test-runner/experimental.ts(+2 -2)➕
packages/hoppscotch-js-sandbox/src/utils/cage.ts(+26 -0)📝
packages/hoppscotch-js-sandbox/src/web/pre-request/index.ts(+2 -2)📝
packages/hoppscotch-js-sandbox/src/web/test-runner/index.ts(+2 -2)📄 Description
Closes #5760
Closes FE-1116
Memory usage with the experimental scripting sandbox spirals out of control during collection runs. Profiling revealed ~30GB allocations for just 5 requests, which eventually caused the tab to crash. This PR addresses the root causes.
What's changed
FaradayCageinstance viaacquireCage()to avoid repeated WASM module allocations. Tests use fresh cages to avoid QuickJS GC corruption.effectScopeto properly dispose computed refs, debounced watchers, and inner watchers on re-initialisation. The previous nested-watcher structure created new watchers on every tab switch without cleanup, causing watcher and timer accumulation.Array.includes()(O(n)) toSet.has()(O(1)) for variable existence checks — noticeable when you have 100+ environment variables.editorModel.dispose()on unmount to clean up script editor instances.Notes to reviewers
Use this sample collection for profiling, which has 5 identical requests with a relatively heavy pre-request script.
Profiling showed a memory drop from ~30GB to ~4GB for the above collection run (86% reduction). The tab no longer crashes.
Summary by cubic
Fixes runaway memory usage in the experimental scripting sandbox by caching and serialising access to the WASM cage, and cleaning up reactive watchers and editor models. Memory drops from ~30GB to ~4GB for a 5-request run, preventing tab crashes and meeting FE-1116 and #5760.
Set.hasfor environment variable checks in the inspector to avoid costly scans.Written for commit
b19f85f2c5. Summary will update on new commits.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.