frankenphp
frankenphp copied to clipboard
Mysql as gone away
Hey guys,
I'm using the API-platform way of using frankenphp to create an API managing a MYSQL database,
My issue is that after a long time of inactivity (in dev environment for example) the mysql server closes the connection.
Since the connection seems to stay opened due to frankenphp. I get a "Mysql has gone away" after the wait_timeout as been reached I don't really now how it would be possible to renew the connection automatically. But I think it would be the way here ?
here is my doctrine configuration file if needed :
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '15'
profiling_collect_backtrace: '%kernel.debug%'
orm:
auto_generate_proxy_classes: true
enable_lazy_ghost_objects: true
report_fields_where_declared: true
validate_xml_mapping: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
when@test:
doctrine:
dbal:
# "TEST_TOKEN" is typically set by ParaTest
dbname_suffix: '_test%env(default::TEST_TOKEN)%'
when@prod:
doctrine:
orm:
auto_generate_proxy_classes: false
proxy_dir: '%kernel.build_dir%/doctrine/orm/Proxies'
query_cache_driver:
type: pool
pool: doctrine.system_cache_pool
result_cache_driver:
type: pool
pool: doctrine.result_cache_pool
framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.app
doctrine.system_cache_pool:
adapter: cache.system
I'm new to frankenphp so I don't understand all the basics of how it works, so if my issue is not where it should be I apologize in advance.
Here is the complete log in case :
{
"channel": "request",
"context":
{
"exception":
{
"class": "Doctrine\\DBAL\\Exception\\ConnectionLost",
"code": 2006,
"file": "/app/vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php:104",
"message": "An exception occurred while executing a query: SQLSTATE[HY000]: General error: 2006 MySQL server has gone away",
"previous":
{
"class": "Doctrine\\DBAL\\Driver\\PDO\\Exception",
"code": 2006,
"file": "/app/vendor/doctrine/dbal/src/Driver/PDO/Exception.php:28",
"message": "SQLSTATE[HY000]: General error: 2006 MySQL server has gone away",
"previous":
{
"class": "PDOException",
"code": 0,
"file": "/app/vendor/doctrine/dbal/src/Driver/PDO/Statement.php:130",
"message": "SQLSTATE[HY000]: General error: 2006 MySQL server has gone away"
}
}
}
},
"datetime": "2023-11-02T19:24:21.790899+01:00",
"extra":
{
},
"level": 500,
"level_name": "CRITICAL",
"message": "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 /app/vendor/doctrine/dbal/src/Driver/API/MySQL/ExceptionConverter.php line 104"
}
Related: #233
Fixed by https://github.com/symfony/symfony/pull/53214.
Hello @dunglas, I still face the issue when using Symfony 7.1 and frankenphp:1-php8.3 docker image. After a while, I get the message that the "MySQL server went away". Should it be solved and I might be missing something?
Be sure to use a version of DoctrineBundle that contains the fix. Last time I checked this was the dev version.
Thank you, yes, it seems it will be released in 2.13 soon if I'm not mistaken: https://github.com/doctrine/DoctrineBundle/compare/2.12.x...2.13.x
Hi there,
we see the same issue, but with https://packagist.org/packages/doctrine/doctrine-bundle#2.13.x-dev Normally, the application should either reconnect to the database or send kind of keepalives/ping to the database. We don't see this behavior on vanilla-php-fpm container..
Any ideas? Perhaps @dunglas ? :)
Short update: as workaround, I increased wait_timeout on mysql side, but that it's quite dirty..