Skip to content

DB + webservice deployment timing failure: connection refused #1

Description

@starmorph

When first deploying the naive web service + DB, there was a timing error that led to the error message below. When I redeployed the web server it immediately fixed it.

codex explanation:

Root cause: the service failed during startup because packages/naive-agent/src/server.ts calls await migrate() before starting the HTTP server. migrate() runs active.query(sql) in shared/db/src/index.ts, which opened the Postgres pool and got:
ECONNREFUSED 10.230.127.113:5432
That means TCP reached the internal Render Postgres address, but nothing was accepting connections on port 5432 at that moment. This was not a build issue, not a port-binding issue, and likely not bad credentials. Bad credentials would show auth errors; external/internal URL mixups usually show latency/SSL/network symptoms, not this exact private-IP refusal.

error message

==> Cloning from https://github.com/starmorph/workflow-agents-workshop-ts
==> Checking out commit b16c0b165c2c80c749c328edccdcc00a016d821a in branch main
==> Requesting Node.js version >=22.12.0
==> Using Node.js version 26.3.0 via /opt/render/project/src/package.json
==> Docs on specifying a Node.js version: https://render.com/docs/node-version
==> Installing Node.js version 26.3.0...
==> Running build command 'npm ci'...
added 127 packages, and audited 134 packages in 4s
32 packages are looking for funding
  run npm fund for details
found 0 vulnerabilities
==> Uploading build...
==> Uploaded in 2.8s. Compression took 1.9s
==> Build successful 🎉
==> Deploying...
==> Setting WEB_CONCURRENCY=1 by default, based on available CPUs in the instance
==> Running 'npm run start --workspace @workshop/naive-agent'
> @workshop/naive-agent@1.0.0 start
> node --import tsx src/server.ts
/opt/render/project/src/node_modules/pg-pool/index.js:45
    Error.captureStackTrace(err)
          ^
Error: connect ECONNREFUSED 10.230.127.113:5432
    at /opt/render/project/src/node_modules/pg-pool/index.js:45:11
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
    at async migrate (/opt/render/project/src/shared/db/src/index.ts:44:3)
    at async <anonymous> (/opt/render/project/src/packages/naive-agent/src/server.ts:99:3) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '10.230.127.113',
  port: 5432
}
Node.js v26.3.0
npm error Lifecycle script start failed with error:
npm error code 1
npm error path /opt/render/project/src/packages/naive-agent
npm error workspace @workshop/naive-agent@1.0.0
npm error location /opt/render/project/src/packages/naive-agent
npm error command failed
npm error command sh -c node --import tsx src/server.ts
==> Instance srv-d8pec9c8aovs73egbls0-7l6vc restarted
==> Exited with status 1
==> Common ways to troubleshoot your deploy: https://render.com/docs/troubleshooting-deploys
==> Running 'npm run start --workspace @workshop/naive-agent'
> @workshop/naive-agent@1.0.0 start
> node --import tsx src/server.ts
/opt/render/project/src/node_modules/pg-pool/index.js:45
    Error.captureStackTrace(err)
          ^
Error: connect ECONNREFUSED 10.230.127.113:5432
    at /opt/render/project/src/node_modules/pg-pool/index.js:45:11
    at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
    at async migrate (/opt/render/project/src/shared/db/src/index.ts:44:3)
    at async <anonymous> (/opt/render/project/src/packages/naive-agent/src/server.ts:99:3) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '10.230.127.113',
  port: 5432
}
Node.js v26.3.0
npm error Lifecycle script start failed with error:
npm error code 1
npm error path /opt/render/project/src/packages/naive-agent
npm error workspace @workshop/naive-agent@1.0.0
npm error location /opt/render/project/src/packages/naive-agent
npm error command failed
npm error command sh -c node --import tsx src/server.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions