Skip to content

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

@sad270

Description

@sad270

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 php/frankenphp#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.

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