Skip to content

[Bug]: KnexTimeoutError on fresh Medusa v2.13.1 install (PostgreSQL reachable, retries loop forever) #14829

@davetheswede

Description

@davetheswede

Package.json file

{
  "name": "redacted-medusa",
  "version": "0.0.1",
  "description": "A starter for Medusa projects.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "build": "medusa build",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "medusa start",
    "dev": "medusa develop",
    "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "2.13.1",
    "@medusajs/cli": "2.13.1",
    "@medusajs/framework": "2.13.1",
    "@medusajs/medusa": "2.13.1"
  },
  "devDependencies": {
    "@medusajs/test-utils": "2.13.1",
    "@swc/core": "^1.7.28",
    "@swc/jest": "^0.2.36",
    "@types/jest": "^29.5.13",
    "@types/node": "^20.12.11",
    "@types/react": "^18.3.2",
    "@types/react-dom": "^18.2.25",
    "jest": "^29.7.0",
    "prop-types": "^15.8.1",
    "react": "^18.3.1",
    "react-dom": "^18.3.1",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2",
    "vite": "^5.4.14",
    "yalc": "^1.0.0-pre.53"
  },
  "engines": {
    "node": ">=20"
  },
  "packageManager": "npm@11.10.1"
}

Node.js version

v22.22.0

Database and its version

17.5 (Debian 17.5-1.pgdg110+1)

Operating system name and version

Ubuntu 26.04

Browser name

No response

What happended?

fter creating a fresh Medusa project (v2.13.1) and configuring PostgreSQL, the server never becomes healthy.
On startup it repeatedly retries DB connection and then fails with KnexTimeoutError (SELECT 1) / Timeout acquiring a connection.
This happens both with direct PostgreSQL connection and via PgBouncer.

Expected behavior

Medusa should establish a DB pool and start successfully when PostgreSQL is reachable and credentials are valid.

In this environment:

  • direct PostgreSQL connection works (psql to :6543, SELECT 1 OK)
  • PgBouncer connection works (psql to :6432, SELECT 1 OK)
  • PostgreSQL is not saturated (max_connections=100, low active sessions)

PostgreSQL connectivity is verified outside Medusa (direct + PgBouncer), so this appears to be in Medusa/Knex pool initialization rather than DB reachability.

Given the above, Medusa startup should complete and /health should return 200.

Actual behavior

Pg connection failed to connect to the database. Retrying... {"name":"KnexTimeoutError","sql":"SELECT 1"}
Knex: Timeout acquiring a connection. The pool is probably full. Are you missing a .transacting(trx) call?

Link to reproduction repo

N/A for now (fresh create-medusa-app scaffold + minimal config).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions