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:
mindesbunister
2025-07-18 12:15:59 +02:00
parent 1a7bdb4109
commit 1b0d92d6ad
5 changed files with 172 additions and 3 deletions

View File

@@ -74,9 +74,14 @@ RUN chmod +x node_modules/.bin/*
# Expose port
EXPOSE 3000
# Copy startup script
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
# Set environment variables for Puppeteer
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
ENV PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium
ENV DOCKER_ENV=true
# Start the app (default to development mode)
CMD ["npm", "run", "dev:docker"]
# Start the app with cleanup handlers
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]