-
Notifications
You must be signed in to change notification settings - Fork 98
Description
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.
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.