Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 15, 2025

The application was freezing during startup at "Creating marketing queue for region" when running in Docker environments, particularly after configuring SMTP services. This occurred because the BullMQ Worker constructor would hang indefinitely when Redis connections experienced delays or failures.

Root Cause

The issue was in the EmailQueueService.initializeQueue() method where:

  • No timeout protection for Redis connections or BullMQ queue/worker creation
  • Synchronous initialization could hang indefinitely on connection issues
  • Missing error handlers for Redis connection failures
  • Docker networking delays causing connection hangs without recovery

Solution

1. Redis Connection Resilience

  • Added 10-second connection timeout with connectTimeout: 10000
  • Implemented comprehensive error event handlers for connection monitoring
  • Added connection status logging for better debugging
  • Used lazyConnect: true for improved connection management

2. Timeout Protection for Queue Initialization

  • Made initializeQueue() asynchronous with 15-second timeout wrapper
  • Added createQueueAndWorkerWithTimeout() method to prevent indefinite hangs
  • Implemented proper error handling and logging throughout the initialization process

3. Enhanced Error Handling

  • Added error event handlers for both Queue and Worker instances
  • Improved logging with detailed context (region, queue name, quotas)
  • Added graceful error handling in instrumentation.ts to prevent app crashes

4. Production Readiness

  • Application now fails fast with clear error messages instead of hanging
  • Maintains backward compatibility with existing configurations
  • Works correctly in Docker environments with service dependency timing

Testing

The fix ensures the application will either:

  1. ✅ Start successfully when Redis is available
  2. ⚡ Fail fast with clear error messages when Redis is unavailable (15s timeout)
  3. 🚫 Never hang indefinitely during startup

This is particularly important for Docker deployments where container networking can introduce connection delays.

Fixes #231.

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:

  • binaries.prisma.sh
  • googlechromelabs.github.io
    • Triggering command: node install.mjs (dns block)
  • https://storage.googleapis.com/chrome-for-testing-public/127.0.6533.88/linux64/chrome-linux64.zip
    • Triggering command: node install.mjs (http block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copy link
Contributor Author

Copilot AI commented Sep 15, 2025

@KMKoushik 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copy link

vercel bot commented Sep 15, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
unsend-marketing Ready Ready Preview Comment Sep 15, 2025 8:59pm

Copy link

cloudflare-workers-and-pages bot commented Sep 15, 2025

Deploying usesend with  Cloudflare Pages  Cloudflare Pages

Latest commit: d6c2274
Status: ✅  Deploy successful!
Preview URL: https://8df8d5a5.usesend.pages.dev
Branch Preview URL: https://copilot-fix-231.usesend.pages.dev

View logs

@Copilot Copilot AI changed the title [WIP] 🐞 - Startup freezes 🐞 Fix startup freeze in EmailQueueService during Redis connection Sep 15, 2025
@Copilot Copilot AI requested a review from KMKoushik September 15, 2025 21:00
@KMKoushik KMKoushik closed this Sep 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐞 - Startup freezes

2 participants