Skip to content

Close PostgreSQL clients in roles and one-time org notifications #2278

@pmjnt

Description

@pmjnt

Hi, I found and patched a small connection lifecycle issue in two backend paths.

Patch branch:
https://github.com/pmjnt/capgo/tree/codex/capgo-audit-next

Commit:
pmjnt@164d8366d

Summary:

  • sendNotifToOrgMembersOnce() creates a dedicated getPgClient(c) write client for one-time org notification claim checks and recipient discovery, but several early returns did not close that pool.
  • supabase/functions/_backend/private/roles.ts creates pg clients for both roles list endpoints without a finally close.
  • The patch wraps the one-time notification path in try/finally, calls closeClient(c, writePgClient), and adds finally cleanup for both private roles endpoints.
  • The unit test now asserts the notification write client is released on early return paths.

Why it matters:
Repeated one-time notification sends or /private/roles requests can leave PostgreSQL pools open longer than intended, which can increase connection pressure in cron/admin/RBAC flows.

Verification:

node_modules/.bin/vitest.exe run tests/org-email-notifications-send-once.unit.test.ts tests/private-rbac-auth-order.unit.test.ts
node_modules/.bin/eslint.exe supabase/functions/_backend/utils/org_email_notifications.ts supabase/functions/_backend/private/roles.ts tests/org-email-notifications-send-once.unit.test.ts
git diff --check

I tried opening a PR from the fork, but GitHub returned:
pmjnt does not have the correct permissions to execute CreatePullRequest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    Inbox

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions