frankenphp icon indicating copy to clipboard operation
frankenphp copied to clipboard

FrankenPHP + Postgres: no connection to the server

Open darkweak opened this issue 2 years ago • 7 comments

Hello, I experiencing some stuff using FrankenPHP but I'm facing an issue that causes Symfony throw a critical error.

Stack:

  • API Platform base
  • Postgresql (tried with 15 and 14)
  • FrankenPHP
  • Swarm cluster (docker container based on alpine)
{
    "channel": "request",
    "context": {
        "exception": {
            "class": "Doctrine\\DBAL\\Exception\\DriverException",
            "code": 7,
            "file": "/app/vendor/doctrine/dbal/src/Driver/API/PostgreSQL/ExceptionConverter.php:87",
            "message": "An exception occurred while executing a query: SQLSTATE[HY000]: General error: 7 no connection to the server",
            "previous": {
                "class": "Doctrine\\DBAL\\Driver\\PDO\\Exception",
                "code": 7,
                "file": "/app/vendor/doctrine/dbal/src/Driver/PDO/Exception.php:28",
                "message": "SQLSTATE[HY000]: General error: 7 no connection to the server",
                "previous": {
                    "class": "PDOException",
                    "code": 0,
                    "file": "/app/vendor/doctrine/dbal/src/Driver/PDO/Statement.php:130",
                    "message": "SQLSTATE[HY000]: General error: 7 no connection to the server"
                }
            }
        }
    },
    "datetime": "2023-12-24T12:46:50.768750+00:00",
    "extra": {},
    "level": 500,
    "level_name": "CRITICAL",
    "message": "Uncaught PHP Exception Doctrine\\DBAL\\Exception\\DriverException: \"An exception occurred while executing a query: SQLSTATE[HY000]: General error: 7 no connection to the server\" at /app/vendor/doctrine/dbal/src/Driver/API/PostgreSQL/ExceptionConverter.php line 87"
}

The error is thrown after about 10-15 minutes running.
Using directly caddy without FrankenPHP works well but I can't explain it because if I go on the container and type bin/console do:q:sql "SELECT * FROM table" it gets the results from db without any issues.
Any ideas about that ?

darkweak avatar Dec 24 '23 12:12 darkweak

Hi,

This is likely a duplicate of https://github.com/dunglas/frankenphp/issues/290.

This is being fixed in Symfony: https://github.com/symfony/symfony/issues/51661

See https://github.com/dunglas/frankenphp/pull/243 for workarounds.

dunglas avatar Dec 24 '23 13:12 dunglas

I probably missed something (the "workaround") but it still doesn't work with the APP_RUNTIME_MODE (from https://github.com/symfony/symfony/pull/52079) 🤷‍♂️

darkweak avatar Dec 26 '23 18:12 darkweak

This mode is a first step but isn't enough. You must backport the RoadRunner patch. Another alternative seems to be to install the ProxyManager bridge.

dunglas avatar Dec 26 '23 22:12 dunglas

Got the same issue today after running FranketPHP 1.1.0 + Symfony 7.0.3 for a few days (Docker Swarm), however I'm not using "worker mode". The error disappeared only after restarting FranketPHP

lermontex avatar Feb 13 '24 20:02 lermontex

Using FrankenPHP 1.1.0 and Symfony 7.0.3 I get

Uncaught PHP Exception Doctrine\DBAL\Exception\ConnectionLost: "An exception occurred while executing a query: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away" at ExceptionConverter.php line 104 {"exception":"[object] (Doctrine\\DBAL\\Exception\\ConnectionLost(code: 2006): An exception occurred while executing a query: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away at /app/vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php:104)\n[previous exception] [object] (Doctrine\\DBAL\\Driver\\PDO\\Exception(code: 2006): SQLSTATE[HY000]: General error: 2006 MySQL server has gone away at /app/vendor/doctrine/dbal/src/Driver/PDO/Exception.php:28)\n[previous exception] [object] (PDOException(code: HY000): SQLSTATE[HY000]: General error: 2006 MySQL server has gone away at /app/vendor/doctrine/dbal/src/Driver/PDO/Connection.php:71)"}

I get the error on my staging server where it is running in worker mode, This is the worker.Caddyfile

worker {
	file ./public/index.php
	env APP_RUNTIME Runtime\FrankenPhpSymfony\Runtime
}

And the production part of the Dockerfile

# Prod FrankenPHP image
FROM frankenphp_base AS frankenphp_prod

ENV APP_ENV=prod
ENV FRANKENPHP_CONFIG="import worker.Caddyfile"

RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"

COPY --from=build_node ./app ./

COPY --link docker/php/conf.d/app.prod.ini $PHP_INI_DIR/conf.d/
COPY --link docker/php/worker.Caddyfile /etc/caddy/worker.Caddyfile

It is trying to connect to a MariaDB10.4 Database.

DennisdeBest avatar Feb 25 '24 11:02 DennisdeBest

@DennisdeBest see https://github.com/symfony/symfony/pull/53214

dunglas avatar Feb 25 '24 11:02 dunglas

@DennisdeBest see symfony/symfony#53214

Thanks I'll keep an eye on that

DennisdeBest avatar Feb 25 '24 12:02 DennisdeBest

Fixed by https://github.com/symfony/symfony/pull/53214.

dunglas avatar Apr 25 '24 09:04 dunglas