Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

abimaelmartell
Copy link
Collaborator

@abimaelmartell abimaelmartell commented Oct 5, 2025

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.

  • Bug Fixes
    • Removed fallback to PORT; worker now binds strictly to EXTRACT_WORKER_PORT (default 3005) and the harness sets it.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a 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`&#39;s liveness server is `3005`, which is the same port used by the `queue-worker` service&#39;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 ?? &quot;3005&quot;) 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");
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Oct 5, 2025

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`&#39;s liveness server is `3005`, which is the same port used by the `queue-worker` service&#39;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(&quot;/liveness&quot;, (req, res) =&gt; {
 });
 
-const workerPort = process.env.EXTRACT_WORKER_PORT || process.env.PORT || 3005;
+const workerPort = Number(process.env.EXTRACT_WORKER_PORT ?? &quot;3005&quot;);
 app.listen(workerPort, () =&gt; {
   _logger.info(`Liveness endpoint is running on port ${workerPort}`);
</file context>
Fix with Cubic

});

const workerPort = process.env.EXTRACT_WORKER_PORT || process.env.PORT || 3005;
const workerPort = Number(process.env.EXTRACT_WORKER_PORT ?? "3005");
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot Oct 5, 2025

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 ?? &quot;3005&quot;) 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(&quot;/liveness&quot;, (req, res) =&gt; {
 });
 
-const workerPort = process.env.EXTRACT_WORKER_PORT || process.env.PORT || 3005;
+const workerPort = Number(process.env.EXTRACT_WORKER_PORT ?? &quot;3005&quot;);
 app.listen(workerPort, () =&gt; {
   _logger.info(`Liveness endpoint is running on port ${workerPort}`);
</file context>
Suggested change
const workerPort = Number(process.env.EXTRACT_WORKER_PORT ?? "3005");
const workerPort = Number(process.env.EXTRACT_WORKER_PORT === "" ? "3005" : process.env.EXTRACT_WORKER_PORT ?? "3005");
Fix with Cubic

@Chadha93
Copy link
Collaborator

@abimaelmartell, this change will cause an issue with queue-worker. When testing for the issue #2251, was port 3002 already in use? You can simply check and kill the port and restart the server to fix it. And if you require the port to be used for another service, you can update it in the env instead.

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.

[Self-Host] firecrawl api starts up and exists after just running

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.