feat: implement robust browser process cleanup system
- Add cleanup-chromium.sh script for manual zombie process cleanup - Add docker-entrypoint.sh with signal handlers for graceful shutdown - Add lib/process-cleanup.ts for automatic cleanup on app termination - Enhanced forceCleanup() method in tradingview-automation.ts: - Individual page closing before browser termination - Force kill remaining processes with SIGKILL - Reset operation locks after cleanup - Improved browser launch args to prevent zombie processes: - Better crash reporter handling - Enhanced background process management - Removed problematic --single-process flag - Updated Dockerfile to use new entrypoint with cleanup handlers - Set DOCKER_ENV environment variable for container detection - Add proper signal handling (SIGINT, SIGTERM, SIGQUIT) - Automatic cleanup of temporary Puppeteer profiles Resolves zombie Chromium process accumulation issue
This commit is contained in:
@@ -124,7 +124,19 @@ export class TradingViewAutomation {
|
||||
'--disable-default-apps',
|
||||
'--disable-sync',
|
||||
'--window-size=1920,1080',
|
||||
'--user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'
|
||||
'--user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
|
||||
// Additional flags to prevent zombie processes
|
||||
'--disable-background-networking',
|
||||
'--disable-background-timer-throttling',
|
||||
'--disable-backgrounding-occluded-windows',
|
||||
'--disable-breakpad',
|
||||
'--disable-client-side-phishing-detection',
|
||||
'--disable-component-extensions-with-background-pages',
|
||||
'--disable-crash-reporter',
|
||||
'--disable-hang-monitor',
|
||||
'--disable-prompt-on-repost',
|
||||
'--no-crash-upload'
|
||||
// Removed --single-process as it causes issues with Puppeteer
|
||||
]
|
||||
})
|
||||
|
||||
@@ -148,7 +160,24 @@ export class TradingViewAutomation {
|
||||
console.log('🧹 Force cleanup: Closing browser and resetting state...')
|
||||
try {
|
||||
if (this.browser) {
|
||||
// First, close all pages
|
||||
const pages = await this.browser.pages()
|
||||
for (const page of pages) {
|
||||
try {
|
||||
await page.close()
|
||||
} catch (e) {
|
||||
console.log('WARNING: Error closing page:', e)
|
||||
}
|
||||
}
|
||||
|
||||
// Then close the browser
|
||||
await this.browser.close()
|
||||
|
||||
// Force kill any remaining processes
|
||||
const browserProcess = this.browser.process()
|
||||
if (browserProcess && !browserProcess.killed) {
|
||||
browserProcess.kill('SIGKILL')
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.log('WARNING: Error during browser cleanup:', e)
|
||||
@@ -157,6 +186,7 @@ export class TradingViewAutomation {
|
||||
this.browser = null
|
||||
this.page = null
|
||||
this.isAuthenticated = false
|
||||
this.operationLock = false
|
||||
console.log('✅ Cleanup completed')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user