Skip to content

[Mocha] Fix PostgreSQL outbox and scheduling authentication with NpgsqlDataSource - #10477

Merged
PascalSenn merged 10 commits into
mainfrom
fix/postgres-outbox-worker-auth
Oct 6, 2026
Merged

PascalSenn merged 10 commits into
mainfrom
fix/postgres-outbox-worker-auth

Conversation

@tobias-tengler

@tobias-tengler tobias-tengler commented Oct 4, 2026 •

Copy link
Copy Markdown
Member

When EF Core uses an NpgsqlDataSource, the PostgreSQL outbox and scheduling workers rebuild their data source from a connection string that omits the password by default (Persist Security Info=false). This loses credentials and authentication callbacks, causing authentication failures and leaving committed and scheduled messages undelivered. Both workers also keep a connection open while idle.

This PR clones the context's configured connection and reuses it while draining due messages, preserving authentication and data source settings. The connection and scope are disposed before idle waits, leaving the configured data source intact.

Copilot AI balanced review requested due to automatic review settings October 4, 2026 09:24
@tobias-tengler tobias-tengler changed the title Fix PostgreSQL outbox worker authentication [Mocha] Fix PostgreSQL outbox worker authentication Oct 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The implementation addresses the authentication regression while preserving connection ownership and covering the relevant configurations and lifecycle behavior.

Review effort: Balanced
Findings: None

What changed in this PR

Fixes PostgreSQL outbox authentication by preserving the EF Core context’s Npgsql configuration when creating worker connections.

Changes:

  • Replaces connection-string reconstruction with cloned dedicated connections.
  • Adds safe connection-failure logging and reliable disposal.
  • Adds integration coverage for authentication, retries, pooling, transactions, and ownership.
File Description
PostgresOutboxWorkerAuthenticationTests.cs Adds PostgreSQL authentication and lifecycle tests.
OutboxServiceRegistrationTests.cs Verifies the connection factory configuration.
PostgresMessageOutboxOptions.cs Replaces the connection string with a connection factory.
OutboxServiceCollectionExtensions.cs Clones the configured Npgsql connection.
MessageBusOutboxWorker.cs Uses, logs, retries, and disposes dedicated connections.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@tobias-tengler
tobias-tengler marked this pull request as draft October 4, 2026 10:12
@github-actions

github-actions Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Patch coverage

100.0% of changed lines covered (75/75)

File Covered Changed Patch %
…/Outbox/MessageBusOutboxWorker.cs 3 3 100.0% 🟢
…/Mocha.EntityFrameworkCore.Postgres/Outbox/OutboxProcessor.cs 26 26 100.0% 🟢
…/Outbox/OutboxServiceCollectionExtensions.cs 9 9 100.0% 🟢
…/Outbox/PostgresMessageOutboxOptions.cs 1 1 100.0% 🟢
…/Scheduling/PostgresScheduledMessageOptions.cs 1 1 100.0% 🟢
…/Scheduling/ScheduledMessageDispatcher.cs 23 23 100.0% 🟢
…/Scheduling/ScheduledMessageWorker.cs 3 3 100.0% 🟢
…/Scheduling/SchedulingServiceCollectionExtensions.cs 9 9 100.0% 🟢

Project coverage: 58.5% (313773/536038 lines)

@tobias-tengler
tobias-tengler force-pushed the fix/postgres-outbox-worker-auth branch from 527151e to 38fa19f Compare October 6, 2026 15:30
@tobias-tengler tobias-tengler changed the title [Mocha] Fix PostgreSQL outbox worker authentication [Mocha] Fix PostgreSQL outbox authentication with NpgsqlDataSource Oct 6, 2026
@tobias-tengler
tobias-tengler marked this pull request as ready for review October 6, 2026 16:16
@tobias-tengler tobias-tengler changed the title [Mocha] Fix PostgreSQL outbox authentication with NpgsqlDataSource [Mocha] Fix PostgreSQL outbox and scheduling authentication with NpgsqlDataSource Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants