Fix JavaScript heap out of memory errors in browser tests#569
Merged
kobenguyent merged 3 commits intomasterfrom Sep 1, 2025
Merged
Fix JavaScript heap out of memory errors in browser tests#569kobenguyent merged 3 commits intomasterfrom
kobenguyent merged 3 commits intomasterfrom
Conversation
Co-authored-by: kobenguyent <[email protected]>
- Replace synchronous fs.readFileSync with streaming in get-file.js - Add 10MB file size limit to prevent memory overload - Add memory cleanup for worker processes with bounded arrays - Enhance safe-serialize with memory limits for arrays and objects - Add comprehensive test coverage for memory fixes - Maintain backward compatibility with existing functionality Co-authored-by: kobenguyent <[email protected]>
Copilot
AI
changed the title
[WIP] error when running browser tests - FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
Fix JavaScript heap out of memory errors in browser tests
Sep 1, 2025
|
🎉 This PR is included in version 1.3.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses critical memory management issues that were causing "JavaScript heap out of memory" errors during browser test execution, particularly when loading file content via the
/api/fileendpoint.Root Causes Identified
The memory issues were caused by several factors:
/api/fileendpoint usedfs.readFileSync()which loads entire files into memory synchronouslyChanges Made
File API Memory Safety
fs.readFileSync()with streamingfs.createReadStream()Worker Process Memory Management
MAX_ERRORS(1000) andMAX_FINISHED_TESTS(500) limits to prevent unbounded array growthArray.shift()to remove oldest entriescleanupWorkerMemory()function for post-test cleanupEnhanced Object Serialization
safe-serializeutility with memory-conscious limits:Before/After Comparison
Before:
After:
Testing
The implementation resolves the heap overflow errors while maintaining full backward compatibility and adding robust memory safeguards throughout the codebase.
Fixes #568.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
googlechromelabs.github.ionode install.mjs(dns block)https://storage.googleapis.com/chrome-for-testing-public/139.0.7258.138/linux64/chrome-headless-shell-linux64.zipnode install.mjs(http block)https://storage.googleapis.com/chrome-for-testing-public/139.0.7258.138/linux64/chrome-linux64.zipnode install.mjs(http block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.