-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(core): clean socket handlers causing memory leaks #899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds comprehensive resource cleanup mechanisms to the Interpreter class. Introduces a new Changes
Sequence DiagramsequenceDiagram
participant Interpreter as Interpreter
participant PopupListener as Popup Listener
participant ConcurrencyMgr as Concurrency Manager
participant Workflow as Workflow Loop
Workflow->>PopupListener: Register listener (runLoop)
activate PopupListener
Note over PopupListener: Waits for popup pages
PopupListener->>ConcurrencyMgr: Route popup page back
ConcurrencyMgr->>Workflow: Enqueue popup page
Workflow->>Workflow: Process popup in workflow
Interpreter->>Interpreter: Error/Abort/Page Close
Interpreter->>Interpreter: Call cleanup()
Interpreter->>Workflow: Stop running workflow
Interpreter->>PopupListener: Remove listener
deactivate PopupListener
Interpreter->>Interpreter: Clear resources (ad-blocker, data)
Interpreter->>Interpreter: Reset state flags
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Tip 📝 Customizable high-level summaries are now available in beta!You can now customize how CodeRabbit generates the high-level summary in your pull requests — including its content, structure, tone, and formatting.
Example instruction:
Note: This feature is currently in beta for Pro-tier users, and pricing will be announced later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
maxun-core/src/interpret.ts (2)
1484-1492: Log errors in the cleanup catch block.The empty catch block silently swallows any errors that occur during cleanup. While cleanup errors are often non-critical, they should still be logged for debugging purposes.
Apply this diff:
const cleanup = () => { try { if (!p.isClosed()) { p.removeListener('popup', popupHandler); } } catch (cleanupError) { + this.log('Failed to remove popup listener', Level.WARN); } };
1736-1742: Consider resetting additional state for complete cleanup.The cleanup method clears data structures and some state flags, but doesn't reset:
screenshotCounterscrapeListCounterconcurrency(should this be recreated or reset?)If the Interpreter instance is intended to be reusable after cleanup, these should also be reset to initial values.
Apply this diff if reusability is intended:
// Clear accumulated data to free memory this.cumulativeResults = []; this.namedResults = {}; this.serializableDataByType = { scrapeList: {}, scrapeSchema: {} }; + + // Reset counters + this.screenshotCounter = 0; + this.scrapeListCounter = 0; // Reset state this.isAborted = false; this.initializedWorkflow = null;
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
maxun-core/src/interpret.ts(5 hunks)
🔇 Additional comments (3)
maxun-core/src/interpret.ts (3)
463-482: LGTM: Proper resource cleanup in enqueueLinks.The addition of the finally block ensures that newly created pages are properly closed even when errors occur, preventing memory leaks. The null-check and isClosed() guard are appropriate.
1729-1729: The review comment is incorrect.Level.DEBUGis properly defined in the logger module.The verification shows:
Level.DEBUGis explicitly defined inmaxun-core/src/utils/logger.tsat line 10 with value95- It's part of the exported
Levelenum (lines 5-12)- It's already used in the logger function signature as a valid parameter type (line 16)
- The import in
interpret.ts(line 17) correctly importsLevelfrom the logger moduleThe code at lines 1729 and 1744 is correct and requires no changes.
1726-1733: Based on my verification, I can now provide the rewritten review comment:
The PlaywrightBlocker instance does not have cleanup or disposal methods in v1.31.3, so setting
this.blocker = nullis the correct approach.The @cliqz/adblocker-playwright v1.31.3 library's public API does not expose any cleanup(), dispose(), or destroy() methods on the PlaywrightBlocker class. The only lifecycle methods available are
enableBlockingInPage(page)anddisableBlockingInPage(page)for managing blocking at the page level, which are already being called appropriately in the codebase (lines 147 and 157). Dereferencing the instance via null assignment is sufficient.The try-catch block around the null assignment is unnecessary, as variable assignment does not throw errors.
ref: #898
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.