dunglas / frankenphp

🧟 The modern PHP app server
https://frankenphp.dev
MIT License
6.62k stars 218 forks source link

FrankenPHP + Postgres: no connection to the server #438

Closed darkweak closed 4 months ago

darkweak commented 8 months ago

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

Stack:

{
    "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 ?

dunglas commented 8 months ago

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.

darkweak commented 8 months ago

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) 🤷‍♂️

dunglas commented 8 months ago

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.

lermontex commented 6 months ago

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

DennisdeBest commented 6 months ago

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.

dunglas commented 6 months ago

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

DennisdeBest commented 6 months ago

@DennisdeBest see symfony/symfony#53214

Thanks I'll keep an eye on that

dunglas commented 4 months ago

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