Conversation
Agent-Logs-Url: https://github.com/obrienma/EventHorizon/sessions/ed3266a5-799a-44b1-8911-977e8c3729dc Co-authored-by: obrienma <3357771+obrienma@users.noreply.github.com>
…worker and server - worker.ts: register uncaughtException/unhandledRejection handlers before startWorker() so ECONNRESET during AMQP startup does not crash the process silently - server.ts: move existing process error handlers to before all top-level awaits so they guard connectDb/connectQueue startup failures - vitest.config.ts: add required env vars to vitest config so config.ts Zod validation passes during unit tests Agent-Logs-Url: https://github.com/obrienma/EventHorizon/sessions/ed3266a5-799a-44b1-8911-977e8c3729dc Co-authored-by: obrienma <3357771+obrienma@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix ECONNRESET error in worker process
fix: register process error handlers before startup awaits to prevent silent ECONNRESET crash
Apr 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Both
workerandserverprocesses were crashing with an unhandledECONNRESETfromamqplib's TCP socket during startup, producing a bare Node.js stack dump with no actionable output.Root causes
worker.tshad nouncaughtException/unhandledRejectionhandlers at all — any rejection fromstartWorker()(includingamqp.connect()failing mid-handshake) was unhandled.server.tshad both handlers, but registered them after theawait connectDb() → connectQueue()chain. A rejection during startup fired before the handlers existed.Changes
src/server.ts— moved both process error handlers to immediately afterFastify()construction, before anyawait. Removed the now-duplicate late registrations.src/processing/worker.ts— addeduncaughtExceptionandunhandledRejectionhandlers before the top-levelawait startWorker().vitest.config.ts— addedenvblock with the minimum required env vars (MONGO_URI,RABBITMQ_URL,EXCHANGE_NAME,QUEUE_NAME,DEAD_LETTER_QUEUE,MONGO_DB_NAME) soconfig.tsZod validation passes at import time during tests. All I/O is mocked; these values never reach real infrastructure.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/home/REDACTED/work/_temp/ghcca-node/node/bin/node node ./postinstall.js(dns block)/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 caused it to exit with code 1. The user then attempted to cancel a previous command, "Delegate to cloud agent." The conversation continued with the user executing the same worker and server commands, leading to the same error being reported again.][Intent Mapping: The user requested to run the worker and server for the Event Horizon project, indicated by the command "[worker] > event-horizon@1.0.0 worker" and "[server] > event-horizon@1.0.0 dev." The user also attempted to cancel a command related to delegating tasks to a cloud agent.]
[Technical Inventory: The user is working with Node.js (version 24.11.1) and TypeScript (tsx) for the Event Horizon project. The commands executed involve starting a worker and server, connecting to a database named "eventhorizon," and ensuring repository indexes.]
[Code Archaeology: The specific files mentioned include "src/processing/worker.ts" and "src/server.ts." The worker file is responsible for processing tasks, while the server file handles incoming requests and WebSocket connections.]
[Progress Assessment: The worker was successfully initiated but encountered an error (ECONNRESET) that caused it to exit. The server appears to be running, as indicated by the successful connection to the database and registration of the WebSocket server.]
[Context Validation: The conversation captures the user's attempts to run the Event Horizon project components and the resulting errors, which are critical for troubleshooting and continuing development.]
[Recent Commands Analysis: The last agent commands executed were:
The tool results indicated that the worker connected to the database but encountered an ECONNRESET error, causing it to exit. The server successfully connected to the database and registered a WebSocket server.]
1. Conversation Overview: - Primary Objectives: The user aimed to run the Event Horizon project's worker and server components, as indicated by the commands executed. The user also attempted to cancel a previous command related to delegating tasks. - Session Context: The conversation involved executing commands to start the worker and server, encountering errors, and attempting to manage command execution. - User Intent Evolution: The user's focus shifted from executing commands to addressing errors encountered during execution.- Technical Foundation:
- Node.js: Version 24.11.1, used for running the Event Horizon project.
- TypeScript (tsx): Utilized for executing TypeScript files in the project.
- Database: "eventhorizon," connected successfully by both the worker and server.
- Codebase Status:
- File Name: src/processing/worker.ts
- Purpose: Handles processing tasks for the Event Horizon project.
- Current State: Encountered an ECONNRESET error during execution.
- File Name: src/server.ts
- Purpose: Manages incoming requests and WebSocket connections.
- Current State: Successfully connected to the database and registered the WebSocket server.
- Problem Resolution:
- Issues Encountered: The worker process faced an ECONNRESET error, causing it to exit unexpectedly.
- Solutions Implemented: No solutions have been applied yet; the user is in the process of troubleshooting the error.
- Debugging Context: The user is actively trying to understand and resolve the ECONNRESET error affecting the worker.
- Progress Tracking:
- Completed Tasks: The server has been successfully started and connected to the database.
- Partially Complete Work: The worker has been initiated but is currently failing due to an error.
- Validated Outcomes: The server's connection to the ...
Created from VS Code.