Skip to content

Fix: PUP_CLUSTER_PORT not set when commonPort is omitted#79

Merged
Hexagon merged 8 commits into
devfrom
copilot/identify-key-areas-for-improvement
Feb 20, 2026
Merged

Fix: PUP_CLUSTER_PORT not set when commonPort is omitted#79
Hexagon merged 8 commits into
devfrom
copilot/identify-key-areas-for-improvement

Conversation

Copy link
Copy Markdown

Copilot AI commented Feb 20, 2026

  • Explore codebase and identify issues
  • Fix cluster.ts: Set PUP_CLUSTER_PORT env var when startPort is defined, regardless of commonPort (fixes issue Deno.env not updated when commonPort omitted in nginx setup #71)
  • Remove duplicated test from pup.test.ts — cluster-specific config tests are in cluster.test.ts
  • Fix formatting: remove unnecessary parentheses in cluster.ts (fixes CI)

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Hexagon and others added 4 commits November 14, 2024 20:12
…mmonPort

Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com>
Copilot AI changed the title [WIP] Identify key areas for improvements Fix: PUP_CLUSTER_PORT not set when commonPort is omitted Feb 20, 2026
Copilot AI requested a review from Hexagon February 20, 2026 22:14
@Hexagon Hexagon changed the base branch from main to dev February 20, 2026 22:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes a bug where the PUP_CLUSTER_PORT environment variable was not being set for cluster instances when commonPort was omitted. Previously, the variable assignment was incorrectly gated on the presence of commonPort, causing all instances to use the same default port and resulting in EADDRINUSE errors when using external load balancers like nginx.

Changes:

  • Decoupled PUP_CLUSTER_PORT environment variable assignment from commonPort in the cluster initialization logic
  • Added test coverage for the fix verifying that PUP_CLUSTER_PORT is correctly set per instance when only startPort is defined

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
lib/core/cluster.ts Updated logic to set PUP_CLUSTER_PORT whenever startPort is defined, regardless of whether the built-in load balancer (commonPort) is active
test/core/pup.test.ts Added test verifying PUP_CLUSTER_PORT is set correctly for each cluster instance when startPort is defined without commonPort

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/core/pup.test.ts Outdated
Comment thread test/core/pup.test.ts Outdated
Comment on lines +125 to +155
@@ -133,14 +134,25 @@ test("Cluster sets PUP_CLUSTER_PORT for each instance without common port", asyn
"cmd": TEST_PROCESS_COMMAND,
"cluster": {
"instances": 2,
"startPort": 8000,
"startPort": START_PORT,
},
},
],
}
const pup = new Pup(config)
await pup.init()

// Find the cluster process
const testCluster = pup.processes.findLast((p) => p.getConfig().id === TEST_PROCESS_ID)
assertNotEquals(testCluster, undefined)
assertEquals(testCluster instanceof Cluster, true)

const cluster = testCluster as Cluster

// Each sub-process should have PUP_CLUSTER_PORT set to startPort + index
assertEquals(cluster.processes.length, 2)
assertEquals(cluster.processes[0].getConfig().env?.PUP_CLUSTER_PORT, String(START_PORT))
assertEquals(cluster.processes[1].getConfig().env?.PUP_CLUSTER_PORT, String(START_PORT + 1))
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test duplicates coverage already provided in test/core/cluster.test.ts at line 13, which tests the exact same scenario: "Cluster with startPort but without commonPort should set PUP_CLUSTER_PORT". The cluster.test.ts version is more thorough, using a loop to verify all instances and testing with 3 instances instead of 2. Since pup.test.ts is for blackbox integration tests of Pup lifecycle behavior (start/stop/block/unblock), cluster-specific configuration tests belong in cluster.test.ts.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the duplicated test from pup.test.ts and cleaned up the unused imports (Cluster, assert). The coverage in cluster.test.ts is more thorough (3 instances, loops over all, checks both with and without commonPort). Commit: dfab675

@Hexagon
Copy link
Copy Markdown
Owner

Hexagon commented Feb 20, 2026

@copilot apply changes based on the comments in this thread

@Hexagon
Copy link
Copy Markdown
Owner

Hexagon commented Feb 20, 2026

@copilot fix tests, formatting etc (ci)

…ter.test.ts)

Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com>
Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Feb 20, 2026

@copilot fix tests, formatting etc (ci)

Fixed in dd5b980deno fmt was failing due to unnecessary parentheses around this.config.cluster.startPort + i on line 74 of cluster.ts.

@Hexagon Hexagon marked this pull request as ready for review February 20, 2026 22:30
@Hexagon Hexagon merged commit 12f7809 into dev Feb 20, 2026
1 check passed
Copilot stopped work on behalf of Hexagon due to an error February 20, 2026 22:30
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.

3 participants