Skip to content

fix(worker): declare RabbitMQ topology before consuming to prevent ECONNRESET - #3

Draft
obrienma with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-econnreset-error
Draft

obrienma with Copilot wants to merge 2 commits into
masterfrom
copilot/fix-econnreset-error

Conversation

Copilot AI commented Apr 1, 2026

Copy link
Copy Markdown

Worker crashed with ECONNRESET on startup because it called ch.consume() against a queue that didn't exist yet — topology was only declared in connectQueue() (server path), so any startup order where the worker leads caused RabbitMQ to close the channel with NOT_FOUND.

Changes

  • queue.ts — extracted topology setup into exported declareTopology(ch: amqp.Channel). connectQueue() delegates to it; no behavioural change for the server path.
  • worker.ts — imports and calls declareTopology(ch) after channel creation, before ch.prefetch() / ch.consume(). Worker is now startup-order-independent.
  • worker.test.ts — adds assertExchange, assertQueue, bindQueue stubs to mockCh to cover the new topology call.
  • vitest.config.ts — adds required env vars so config-dependent test suites (worker, routes, metrics) load correctly; fixes a pre-existing gap that caused those suites to fail before any test ran.
// worker.ts — added before ch.prefetch()
await declareTopology(ch);
// assertExchange/assertQueue are idempotent; safe to call from both server and worker

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:

  • fastdl.mongodb.org
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node ./postinstall.js (dns block)
    • Triggering command: /opt/hostedtoolcache/node/24.14.0/x64/bin/node /opt/hostedtoolcache/node/24.14.0/x64/bin/node --experimental-import-meta-resolve --require /home/REDACTED/work/EventHorizon/EventHorizon/node_modules/vitest/suppress-warnings.cjs --conditions node --conditions development /home/REDACTED/work/EventHorizon/EventHorizon/node_modules/vitest/dist/workers/forks.js (dns block)

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

Original prompt

[worker] > event-horizon@1.0.0 worker
[worker] > tsx src/processing/worker.ts
[worker]
[server]
[server] > event-horizon@1.0.0 dev
[server] > tsx src/server.ts
[server]
[worker] [db] connected to "eventhorizon"
[worker] [repository] indexes ensured
[worker] node:internal/modules/run_main:107
[worker] triggerUncaughtException(
[worker] ^
[worker]
[worker] Error: read ECONNRESET
[worker] at TCP.onStreamRead (node:internal/stream_base_commons:216:20) {
[worker] errno: -104,
[worker] code: 'ECONNRESET',
[worker] syscall: 'read'
[worker] }
[worker]
[worker] Node.js v24.11.1
[worker] npm run worker exited with code 1
[server] [ws] server registered at /ws
[server] [db] connected to "eventhorizon"
[server] [repository] indexes ensured
[server] node:internal/modules/run_main:107
[server] triggerUncaughtException(
[server] ^

The user has attached the following file paths as relevant context:

  • .github/copilot-instructions.md
  • CLAUDE.md
[Chronological Review: The conversation began with the user executing commands to run a worker and server for the Event Horizon project. The worker encountered an error (ECONNRESET) during execution, which led to the user attempting to cancel a previous command and then delegate a task to a cloud agent. The user repeated the command to run the worker and server, encountering the same error again.]

[Intent Mapping: The user explicitly requested to "Delegate to cloud agent" after encountering an error with the worker process. The intent appears to be to offload some tasks or issues to a cloud agent for resolution.]

[Technical Inventory: The conversation involved the following technologies:

  • Node.js v24.11.1: The runtime environment for executing JavaScript code.
  • TypeScript (tsx): Used for running TypeScript files.
  • Event Horizon: The project name, indicating a focus on event-driven architecture.]

[Code Archaeology: The user was working with the following files:

  • src/processing/worker.ts: This file is likely responsible for processing tasks in the worker.
  • src/server.ts: This file is likely responsible for setting up the server for the application.
  • The user was also editing CLAUDE.md, which may contain documentation or notes related to the project.]

[Progress Assessment: The user has attempted to run the worker and server multiple times but has encountered a consistent error (ECONNRESET). The worker process exited with code 1, indicating a failure.]

[Context Validation: The user is trying to resolve issues related to the worker and server processes in the Event Horizon project, specifically dealing with connection errors.]

[Recent Commands Analysis:

  • Last Agent Commands: The user executed the following commands:
    • npm run worker to start the worker process.
    • npm run dev to start the server process.
  • Tool Results Summary: The worker process encountered an "Error: read ECONNRESET" which caused it to exit with code 1. The server registered successfully at /ws but also triggered an uncaught exception.]
1. Conversation Overview: - Primary Objectives: The user aimed to run the Event Horizon project, specifically the worker and server processes, and to delegate tasks to a cloud agent due to encountered errors. - Session Context: The conversation involved executing commands to start the worker and server, encountering connection errors, and attempting to delegate tasks. - User Intent Evolution: The user shifted from trying to resolve the worker error to seeking assistance from a cloud agent.
  1. Technical Foundation:
  • Node.js: Version 24.11.1, used as the runtime environment for the application.
  • TypeScript: Utilized for running TypeScript files with the tsx command.
  • Event Horizon: The project name, indicating an event-driven architecture focus.
  1. Codebase Status:
  • File Name: src/processing/worker.ts
    • Purpose: Responsible for processing tasks in the worker.
    • Current State: Encountered an ECONNRESET error during execution.
  • File Name: src/server.ts
    • Purpose: Sets up the server for the application.
    • Current State: Registered successfully at /ws but also faced an uncaught exception.
  1. Problem Resolution:
  • Issues Encountered: The worker process faced a "read ECONNRESET" error, causing it to exit unexpectedly.
  • Solutions Implemented: The user attempted to restart the worker and server processes and considered delegating tasks to a cloud agent.
  • Debugging Context: The user is actively troubleshooting connection issues with the worker process.
  1. Progress Tracking:
  • Completed Tasks: The user successfully executed commands to start the worker and server, but both encountered errors.
  • Partially Complete Work: The worker process is not functioning due to the ECONNRESET error.
  • Validated Outcomes: The server registered at /ws, but further functionality is hindered by the worker's failure.
  1. Active Work State:
  • Current Focus: The user was attempting to run the work...

Created from VS Code.

Copilot AI changed the title [WIP] Fix ECONNRESET error in worker fix(worker): declare RabbitMQ topology before consuming to prevent ECONNRESET Apr 1, 2026
Copilot AI requested a review from obrienma April 1, 2026 04:40
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.

2 participants