doctrine / doctrine/DoctrineBundle

WorkerMode with Primary Replica Database will not switch back to replica connection

Open
#2,154 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
4.8k
Forks
482
Avg merge
1h 51m
Merged PRs (30d)
3

Description

### Bug Report

#### Summary

When using **FrankenPHP** in **Worker mode** with a Primary / Read Replica connection. If in a http request we do an write action in database, the connection will switch to primary connection and doctrine will switch back to replica on a new http request.

There is a closed issue in Franken PHP repo https://github.com/php/frankenphp/issues/1444 but IMO adding a ` $this->connection->ensureConnectedToReplica();` in the start or the end of each request is a workaround not a fix.

As a developer, I expect that, each new HTTP request will reset the connection and we will be on replica. Like when we are not in worker mode.

#### Current behavior

When cennection switch to primary, it stay connected to Primary on each new HTTP request

#### Expected behavior

Each new HTTP request will be connected to replica even if previous http request did a write action in database

#### How to reproduce

* Run a FrankenPHP server in Worker Mode with a Symfony Application.
* Configure a postgresql server with a read replica
* Add 2 route, one with a `SELECT` the other with a `INSERT` statement
* call the endpoint with the `INSERT` statement
* call the endpoint with the `SELECT` statement
* look primary postgresql logs, you will see the select statement.

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the INSERT-then-SELECT request sequence in a FrankenPHP worker with Symfony and PostgreSQL primary/replica connections. Inspect the request lifecycle and Doctrine connection handling, then verify in the primary PostgreSQL logs that a new request returns to the replica without requiring a per-request workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, postgresql
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.