Repository navigation
perf(worker): consolidate worker processes - #1566
Merged
Merged
Conversation
realcodesiman
force-pushed
the
bugfix/worker-memory-growth
branch
from
October 28, 2026 03:03
0dbfb99 to
cc19684
Compare
…idated modes Drop the implicit 256MB heap cap for legacy all-mode and make WORKER_SHUTDOWN_TIMEOUT_MS optional, defaulting it in the entrypoint only for standalone/core. Raise SHARD_POOL_MAX alongside DATABASE_POOL_MAX, and install source-mapped stacks explicitly from the worker so the logger no longer pulls node:module into every consumer.
Worker tests mock the logger with fatal and stub the business realtime flush so the affected suites pass.
…nsumers Add createQueueWorker so every consumer handles the Worker `error` event (an unhandled one restarts all queues in a consolidated process), logs failures and drains on shutdown. Share one QueueEvents per queue instead of per-queue singletons, and document the shutdown grace period and job lock.
…tack logging createQueueWorker now refuses to start once shutdown has begun, and catches rejections from async onFailed handlers (BullMQ never awaits listeners, so they would surface as unhandledRejection and drain every queue in a consolidated process). Also drops the source-mapped stack mapper from the logger, removes the getHeavyQueueEvents wrapper in favour of getQueueEvents, dedupes the consolidated-mode env defaults in the docker entrypoint, and downgrades the per-job trigger completion log to debug.
Lock durations now cover the full heavy/integration job budgets so slow provider calls are not redelivered mid-run. Fatal-error shutdown is bounded at 30s and sets exitCode, the sequence consumer skips startup after shutdown began, and consolidated DB pool defaults are raised to 80.
…ration failure A shutdown that begins while a worker is still starting could leak the workers, event listeners or scheduler ticks started afterwards. runWorker now skips or tolerates starts that race shutdown, and the events and sequence scheduler entries re-check the shutdown flag after their async startup. A schedule registration failure no longer takes down the shared process. Docs and the pool-ceiling test follow the env-driven pool and heap defaults.
realcodesiman
force-pushed
the
bugfix/worker-memory-growth
branch
from
October 28, 2026 23:24
b624706 to
9758072
Compare
hello-jackytruong
referenced
this pull request
in hello-jackytruong/ChatWorkAI
Nov 22, 2026
* perf(worker): consolidate worker processes * fix(worker): bound consolidated worker memory growth * fix(worker): make heap cap and shutdown timeout opt-in outside consolidated modes Drop the implicit 256MB heap cap for legacy all-mode and make WORKER_SHUTDOWN_TIMEOUT_MS optional, defaulting it in the entrypoint only for standalone/core. Raise SHARD_POOL_MAX alongside DATABASE_POOL_MAX, and install source-mapped stacks explicitly from the worker so the logger no longer pulls node:module into every consumer. * fix(worker): drop source-mapped stack install and update logger mocks Worker tests mock the logger with fatal and stub the business realtime flush so the affected suites pass. * refactor(worker): share queue worker setup and queue events across consumers Add createQueueWorker so every consumer handles the Worker `error` event (an unhandled one restarts all queues in a consolidated process), logs failures and drains on shutdown. Share one QueueEvents per queue instead of per-queue singletons, and document the shutdown grace period and job lock. * fix(worker): harden queue worker lifecycle and remove source-mapped stack logging createQueueWorker now refuses to start once shutdown has begun, and catches rejections from async onFailed handlers (BullMQ never awaits listeners, so they would surface as unhandledRejection and drain every queue in a consolidated process). Also drops the source-mapped stack mapper from the logger, removes the getHeavyQueueEvents wrapper in favour of getQueueEvents, dedupes the consolidated-mode env defaults in the docker entrypoint, and downgrades the per-job trigger completion log to debug. * fix(worker): size job locks to job budgets and bound fatal shutdown Lock durations now cover the full heavy/integration job budgets so slow provider calls are not redelivered mid-run. Fatal-error shutdown is bounded at 30s and sets exitCode, the sequence consumer skips startup after shutdown began, and consolidated DB pool defaults are raised to 80. * fix(worker): close startup/shutdown races and isolate schedule registration failure A shutdown that begins while a worker is still starting could leak the workers, event listeners or scheduler ticks started afterwards. runWorker now skips or tolerates starts that race shutdown, and the events and sequence scheduler entries re-check the shutdown flag after their async startup. A schedule registration failure no longer takes down the shared process. Docs and the pool-ceiling test follow the env-driven pool and heap defaults. * fix(worker): isolate marketing message worker process
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.
Summary
Changes
Test plan