Skip to content

New DB connections on every inspect page refresh #288

@zhuojg

Description

@zhuojg

I'm encountering an issue during local development when using @workflow/world-postgres.

The Postgres Docker container eventually throws an error:

FATAL: sorry, too many clients already

I am using following commands to start inspect server:
WORKFLOW_TARGET_WORLD="@workflow/world-postgres" WORKFLOW_POSTGRES_URL="postgresql://postgres:[email protected]/postgres" npx workflow inspect runs --web

When I inspect the active database connections with:

SELECT * FROM pg_stat_activity;

I notice that each time I refresh the web page, new database connections are created and never reused. The duplicate connections can be observed from this screenshot. And everytime I refresh the page, more connections will appear.

Image

After digging into the code, it appears that the server action in
packages/web-shared/src/api/workflow-server-actions.ts — specifically the getWorldFromEnv function — always creates a new world instance without any caching. As a result, each page refresh spawns a new world instance and eventually exhausts available DB connections.

If this assessment is correct, I'm happy to work on a fix.

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