-
Notifications
You must be signed in to change notification settings - Fork 5k
Fix extract worker port collision with API #2253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 issues found across 2 files
Prompt for AI agents (all 2 issues)
Understand the root cause of the following 2 issues and fix them.
<file name="apps/api/src/services/extract-worker.ts">
<violation number="1" location="apps/api/src/services/extract-worker.ts:289">
This change introduces a port collision with `queue-worker`. The new default port for `extract-worker`'s liveness server is `3005`, which is the same port used by the `queue-worker` service's liveness server, especially in the Docker environment where `WORKER_PORT` is explicitly set to `3005`.</violation>
<violation number="2" location="apps/api/src/services/extract-worker.ts:289">
If EXTRACT_WORKER_PORT is configured but left blank, Number(EXTRACT_WORKER_PORT ?? "3005") coerces it to 0 and the liveness server binds to an ephemeral port, defeating monitoring. Please treat empty values as missing so the default port is used.</violation>
</file>
React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai
to give feedback, ask questions, or re-run the review.
}); | ||
|
||
const workerPort = process.env.EXTRACT_WORKER_PORT || process.env.PORT || 3005; | ||
const workerPort = Number(process.env.EXTRACT_WORKER_PORT ?? "3005"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change introduces a port collision with queue-worker
. The new default port for extract-worker
's liveness server is 3005
, which is the same port used by the queue-worker
service's liveness server, especially in the Docker environment where WORKER_PORT
is explicitly set to 3005
.
Prompt for AI agents
Address the following comment on apps/api/src/services/extract-worker.ts at line 289:
<comment>This change introduces a port collision with `queue-worker`. The new default port for `extract-worker`'s liveness server is `3005`, which is the same port used by the `queue-worker` service's liveness server, especially in the Docker environment where `WORKER_PORT` is explicitly set to `3005`.</comment>
<file context>
@@ -289,7 +286,7 @@ app.get("/liveness", (req, res) => {
});
-const workerPort = process.env.EXTRACT_WORKER_PORT || process.env.PORT || 3005;
+const workerPort = Number(process.env.EXTRACT_WORKER_PORT ?? "3005");
app.listen(workerPort, () => {
_logger.info(`Liveness endpoint is running on port ${workerPort}`);
</file context>
}); | ||
|
||
const workerPort = process.env.EXTRACT_WORKER_PORT || process.env.PORT || 3005; | ||
const workerPort = Number(process.env.EXTRACT_WORKER_PORT ?? "3005"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If EXTRACT_WORKER_PORT is configured but left blank, Number(EXTRACT_WORKER_PORT ?? "3005") coerces it to 0 and the liveness server binds to an ephemeral port, defeating monitoring. Please treat empty values as missing so the default port is used.
Prompt for AI agents
Address the following comment on apps/api/src/services/extract-worker.ts at line 289:
<comment>If EXTRACT_WORKER_PORT is configured but left blank, Number(EXTRACT_WORKER_PORT ?? "3005") coerces it to 0 and the liveness server binds to an ephemeral port, defeating monitoring. Please treat empty values as missing so the default port is used.</comment>
<file context>
@@ -289,7 +286,7 @@ app.get("/liveness", (req, res) => {
});
-const workerPort = process.env.EXTRACT_WORKER_PORT || process.env.PORT || 3005;
+const workerPort = Number(process.env.EXTRACT_WORKER_PORT ?? "3005");
app.listen(workerPort, () => {
_logger.info(`Liveness endpoint is running on port ${workerPort}`);
</file context>
const workerPort = Number(process.env.EXTRACT_WORKER_PORT ?? "3005"); | |
const workerPort = Number(process.env.EXTRACT_WORKER_PORT === "" ? "3005" : process.env.EXTRACT_WORKER_PORT ?? "3005"); |
@abimaelmartell, this change will cause an issue with |
Updated the Docker harness to hand the extract worker its own EXTRACT_WORKER_PORT (defaulting to 3005) and made the worker bind to that port instead of inheriting PORT, because the previous behavior caused the extract worker’s liveness server to occupy port 3002 and crash with an EADDRINUSE.
fixes #2251
Summary by cubic
Gave the extract worker a dedicated port via EXTRACT_WORKER_PORT (default 3005) and made its liveness server bind to it to prevent collisions with the API and EADDRINUSE crashes.