feat: implement comprehensive process cleanup system
- Added aggressive cleanup system that runs every 5 minutes to kill orphaned processes - Enhanced process cleanup with better signal handling and forced cleanup - Added startup initialization system to ensure cleanup is properly loaded - Integrated cleanup system into app layouts for automatic initialization - Added zombie process cleanup and temp directory cleanup - Improved Docker container restart behavior for proper process cleanup - Resolves issue with zombie Chrome processes accumulating
This commit is contained in:
@@ -5,6 +5,7 @@ import { tradingViewAutomation } from './tradingview-automation'
|
||||
class ProcessCleanup {
|
||||
private static instance: ProcessCleanup
|
||||
private isShuttingDown = false
|
||||
private aggressiveCleanup: any = null
|
||||
|
||||
private constructor() {
|
||||
// Register cleanup handlers
|
||||
@@ -13,6 +14,18 @@ class ProcessCleanup {
|
||||
process.on('SIGQUIT', this.handleShutdown.bind(this))
|
||||
process.on('uncaughtException', this.handleError.bind(this))
|
||||
process.on('unhandledRejection', this.handleError.bind(this))
|
||||
|
||||
// Lazy load aggressive cleanup to avoid circular imports
|
||||
this.loadAggressiveCleanup()
|
||||
}
|
||||
|
||||
private async loadAggressiveCleanup() {
|
||||
try {
|
||||
const { default: aggressiveCleanup } = await import('./aggressive-cleanup')
|
||||
this.aggressiveCleanup = aggressiveCleanup
|
||||
} catch (error) {
|
||||
console.error('Failed to load aggressive cleanup:', error)
|
||||
}
|
||||
}
|
||||
|
||||
static getInstance(): ProcessCleanup {
|
||||
@@ -32,6 +45,12 @@ class ProcessCleanup {
|
||||
console.log(`\n🛑 Received ${signal}, initiating graceful shutdown...`)
|
||||
|
||||
try {
|
||||
// Use aggressive cleanup first
|
||||
if (this.aggressiveCleanup) {
|
||||
console.log('🧹 Running aggressive cleanup...')
|
||||
await this.aggressiveCleanup.forceCleanup()
|
||||
}
|
||||
|
||||
// Clean up screenshot service
|
||||
console.log('🧹 Cleaning up screenshot service...')
|
||||
await enhancedScreenshotService.cleanup()
|
||||
@@ -53,6 +72,9 @@ class ProcessCleanup {
|
||||
|
||||
// Attempt cleanup
|
||||
try {
|
||||
if (this.aggressiveCleanup) {
|
||||
await this.aggressiveCleanup.forceCleanup()
|
||||
}
|
||||
await enhancedScreenshotService.cleanup()
|
||||
await tradingViewAutomation.forceCleanup()
|
||||
} catch (cleanupError) {
|
||||
|
||||
Reference in New Issue
Block a user