Skip to content

Deno.env not updated when commonPort omitted in nginx setup #71

@lockphase

Description

@lockphase

I setup an aws ec2 instance with 2CPUs for cluster testing (deno + pup with AL2023 kernel-6.1 AMI). Testing with the sample pup.json config in examples is wai, see below logs.

2025-10-03T05:13:27.018Z [LOG] [core:processes] Cluster 'test' loading
2025-10-03T05:13:27.019Z [LOG] [core:cluster] Sub-Process 'test-1' loaded
2025-10-03T05:13:27.020Z [LOG] [core:cluster] Sub-Process 'test-2' loaded
2025-10-03T05:13:27.020Z [LOG] [test:cluster] Setting up load balancer for 2 instances with common port 3000 and strategy ROUND_ROBIN
2025-10-03T05:13:27.050Z [LOG] [test-1:starting] Process starting, reason: autostart
2025-10-03T05:13:27.052Z [LOG] [test-2:starting] Process starting, reason: autostart
2025-10-03T05:13:27.062Z [INFO] [core:api-rest] Starting the Rest API on 127.0.0.1:49152
2025-10-03T05:13:27.014Z [INFO] [core:rest] Initializing rest api
2025-10-03T05:13:27.145Z [LOG] [test-2:stdout] 8001
2025-10-03T05:13:27.152Z [ERROR] [test-2:stderr] Listening on http://0.0.0.0:8001/ (http://localhost:8001/)
2025-10-03T05:13:27.148Z [LOG] [test-2:stdout] 8001
2025-10-03T05:13:27.153Z [LOG] [test-2:stdout] HTTP webserver running on pup instance 1.
2025-10-03T05:13:27.156Z [LOG] [test-2:stdout] Access it at:  http://localhost:8001/
2025-10-03T05:13:27.164Z [ERROR] [test-1:stderr] Listening on http://0.0.0.0:8000/ (http://localhost:8000/)
2025-10-03T05:13:27.162Z [LOG] [test-1:stdout] 8000
2025-10-03T05:13:27.166Z [LOG] [test-1:stdout] 8000
2025-10-03T05:13:27.169Z [LOG] [test-1:stdout] HTTP webserver running on pup instance 0.
2025-10-03T05:13:27.171Z [LOG] [test-1:stdout] Access it at:  http://localhost:8000/

Then, I setup nginx with upstream block (server 127.0.0.1:8000 + server 127.0.0.1:8001) and omitted commonPort from pup.json. Now pup run fails to load.

2025-10-03T05:15:01.050Z [LOG] [core:processes] Cluster 'test' loading
2025-10-03T05:15:01.051Z [LOG] [core:cluster] Sub-Process 'test-1' loaded
2025-10-03T05:15:01.051Z [LOG] [core:cluster] Sub-Process 'test-2' loaded
2025-10-03T05:15:01.052Z [LOG] [test-1:starting] Process starting, reason: autostart
2025-10-03T05:15:01.053Z [LOG] [test-2:starting] Process starting, reason: autostart
2025-10-03T05:15:01.057Z [INFO] [core:api-rest] Starting the Rest API on 127.0.0.1:49152
2025-10-03T05:15:01.045Z [INFO] [core:rest] Initializing rest api
2025-10-03T05:15:01.173Z [LOG] [test-1:stdout] undefined
2025-10-03T05:15:01.178Z [LOG] [test-2:stdout] undefined
2025-10-03T05:15:01.179Z [LOG] [test-2:stdout] 8000
2025-10-03T05:15:01.177Z [LOG] [test-1:stdout] 8000
2025-10-03T05:15:01.184Z [LOG] [test-1:stdout] HTTP webserver running on pup instance 0.
2025-10-03T05:15:01.184Z [LOG] [test-1:stdout] Access it at:  http://localhost:8000/
2025-10-03T05:15:01.185Z [ERROR] [test-2:stderr] error: Uncaught (in promise) AddrInUse: Address already in use (os error 98)
2025-10-03T05:15:01.185Z [ERROR] [test-2:stderr]   Deno.serve({ port: PORT }, () => {
2025-10-03T05:15:01.185Z [ERROR] [test-2:stderr]        ^
2025-10-03T05:15:01.186Z [ERROR] [test-2:stderr]     at listen (ext:deno_net/01_net.js:594:35)
2025-10-03T05:15:01.186Z [ERROR] [test-2:stderr]     at serveInner (ext:deno_http/00_serve.ts:675:16)
2025-10-03T05:15:01.186Z [ERROR] [test-2:stderr]     at Object.serve (ext:deno_http/00_serve.ts:591:10)
2025-10-03T05:15:01.186Z [ERROR] [test-2:stderr]     at file:///home/ec2-user/sb_v2/app.ts:7:8
2025-10-03T05:15:01.189Z [LOG] [test-2:errored] Process exited with error: Error: Exited with code: 1
2025-10-03T05:15:01.184Z [ERROR] [test-1:stderr] Listening on http://0.0.0.0:8000/ (http://localhost:8000/)

My app.ts is similar to examples except for some debugging. This accounts for the double port readout in the logs.

const PORT = parseInt(Deno.env.get("PUP_CLUSTER_PORT") || "8000", 10);

console.log(Deno.env.get("PUP_CLUSTER_PORT"))
console.log(PORT)

It seemed like omitting commonPort is causing Deno.env to not update correctly. If I set commonPort back and ran it against the nginx setup, I can get it to work. But
a) the built in load balancer is running
b) all responses are only being served from 1 port which appears to be the last port setup, see below.

2025-10-03T05:26:26.526Z [LOG] [core:processes] Cluster 'test' loading
2025-10-03T05:26:26.526Z [LOG] [core:cluster] Sub-Process 'test-1' loaded
2025-10-03T05:26:26.526Z [LOG] [core:cluster] Sub-Process 'test-2' loaded
2025-10-03T05:26:26.527Z [LOG] [test:cluster] Setting up load balancer for 2 instances with common port 3000 and strategy ROUND_ROBIN
2025-10-03T05:26:26.558Z [LOG] [test-1:starting] Process starting, reason: autostart
2025-10-03T05:26:26.560Z [LOG] [test-2:starting] Process starting, reason: autostart
2025-10-03T05:26:26.566Z [INFO] [core:api-rest] Starting the Rest API on 127.0.0.1:49152
2025-10-03T05:26:26.521Z [INFO] [core:rest] Initializing rest api
2025-10-03T05:26:26.655Z [LOG] [test-2:stdout] 8001
2025-10-03T05:26:26.663Z [ERROR] [test-2:stderr] Listening on http://0.0.0.0:8001/ (http://localhost:8001/)
2025-10-03T05:26:26.659Z [LOG] [test-2:stdout] 8001
2025-10-03T05:26:26.665Z [LOG] [test-2:stdout] HTTP webserver running on pup instance 1.
2025-10-03T05:26:26.670Z [LOG] [test-1:stdout] 8000
2025-10-03T05:26:26.667Z [LOG] [test-2:stdout] Access it at:  http://localhost:8001/
2025-10-03T05:26:26.672Z [ERROR] [test-1:stderr] Listening on http://0.0.0.0:8000/ (http://localhost:8000/)
2025-10-03T05:26:26.672Z [LOG] [test-1:stdout] 8000
2025-10-03T05:26:26.675Z [LOG] [test-1:stdout] HTTP webserver running on pup instance 0.
2025-10-03T05:26:26.679Z [LOG] [test-1:stdout] Access it at:  http://localhost:8000/
2025-10-03T05:26:43.626Z [LOG] [test-1:stdout] serving from 8000
2025-10-03T05:26:48.025Z [LOG] [test-1:stdout] serving from 8000
2025-10-03T05:26:57.639Z [LOG] [test-1:stdout] serving from 8000
2025-10-03T05:27:01.641Z [LOG] [test-1:stdout] serving from 8000

Did I do smthg wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions