An exception occured in driver: MySQL server has gone away (Doctrine2, Typo3, Kubernetes, cloud sql proxy) #6082

Closed
opened 2026-01-22 15:26:31 +01:00 by admin · 4 comments
Owner

Originally created by @cccdemon on GitHub (Oct 9, 2018).

Proxy Service definition:

kind: Service
apiVersion: v1
metadata:
  name: {{CONTENT_INT_SVC}}
spec:
  selector:
    app: sql-proxy
  ports:
    - protocol: TCP
      port: {{MYSQL_PORT}}
      targetPort: {{CONTENT_INT_SVC}}

Google Cloud Proxy Definition:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: sql-proxy-deployment
  labels:
    app: sql-proxy
spec:
  replicas: 2
  selector:
    matchLabels:
      app: sql-proxy
  template:
    metadata:
      labels:
        app: sql-proxy
    spec:
      containers:
      - name: sql-proxy
        image: gcr.io/cloudsql-docker/gce-proxy:1.10
        command: ["/cloud_sql_proxy",
                  "-instances={{SUPPLIER_DB}}=tcp:0.0.0.0:{{SUPPLIER_INT_PORT}},{{ORDER_DB}}=tcp:0.0.0.0:{{ORDER_INT_PORT}},{{SHOP_MAIN_DB}}=tcp:0.0.0.0:{{SHOP_MAIN_INT_PORT}},{{CONTENT_DB}}=tcp:0.0.0.0:{{CONTENT_INT_PORT}},{{CD_ORDER_DB}}=tcp:0.0.0.0:{{CD_ORDER_INT_PORT}},{{FF_MASTER_DB}}=tcp:0.0.0.0:{{FF_MASTER_INT_PORT}},{{FOREIGN_DB}}=tcp:0.0.0.0:{{FOREIGN_INT_PORT}}",
                  "-credential_file=/secrets/cloudsql/credentials.json"]
        volumeMounts:
        - name: cloudsql-instance-credentials
          mountPath: /secrets/cloudsql
          readOnly: true
        ports:
          - name: {{ORDER_INT_SVC}}
            containerPort: {{ORDER_INT_PORT}}
          - name: {{SUPPLIER_INT_SVC}}
            containerPort: {{SUPPLIER_INT_PORT}}
          - name: {{CONTENT_INT_SVC}}
            containerPort: {{CONTENT_INT_PORT}}
          - name: {{CD_ORDER_INT_SVC}}
            containerPort: {{CD_ORDER_INT_PORT}}
          - name: {{SHOP_MAIN_INT_SVC}}
            containerPort: {{SHOP_MAIN_INT_PORT}}
          - name: {{FF_MASTER_INT_SVC}}
            containerPort: {{FF_MASTER_INT_PORT}}
          - name: {{FOREIGN_INT_SVC}}
            containerPort: {{FOREIGN_INT_PORT}}
      volumes:
      - name: cloudsql-instance-credentials
        secret:
          secretName: service-account-order-db

Exception:

After removing the Proxy and connecting direct to Google Cloud SQL, the connection will work properly.
It seems that

$this->_conn = $this->_driver->connect($this->_params, $user, $password, $driverOptions);
$this->_isConnected = true;`

does not returns the correct state (i dont know why)

PHP Version: 7.1.22
Kubernetes Version 1.9.x
Google Managed Kubnernetes (Autoscaled - thats why we cant use fixed IPs for DB Access)

This issue is happens when you use TYPO3 CMS 8.7.19 on Google Kubernetes with SQL Proxy, install tool - Install tool: Database analyzer

Originally created by @cccdemon on GitHub (Oct 9, 2018). **Proxy Service definition:** ```yml kind: Service apiVersion: v1 metadata: name: {{CONTENT_INT_SVC}} spec: selector: app: sql-proxy ports: - protocol: TCP port: {{MYSQL_PORT}} targetPort: {{CONTENT_INT_SVC}} ``` **Google Cloud Proxy Definition:** ```yml apiVersion: apps/v1 kind: Deployment metadata: name: sql-proxy-deployment labels: app: sql-proxy spec: replicas: 2 selector: matchLabels: app: sql-proxy template: metadata: labels: app: sql-proxy spec: containers: - name: sql-proxy image: gcr.io/cloudsql-docker/gce-proxy:1.10 command: ["/cloud_sql_proxy", "-instances={{SUPPLIER_DB}}=tcp:0.0.0.0:{{SUPPLIER_INT_PORT}},{{ORDER_DB}}=tcp:0.0.0.0:{{ORDER_INT_PORT}},{{SHOP_MAIN_DB}}=tcp:0.0.0.0:{{SHOP_MAIN_INT_PORT}},{{CONTENT_DB}}=tcp:0.0.0.0:{{CONTENT_INT_PORT}},{{CD_ORDER_DB}}=tcp:0.0.0.0:{{CD_ORDER_INT_PORT}},{{FF_MASTER_DB}}=tcp:0.0.0.0:{{FF_MASTER_INT_PORT}},{{FOREIGN_DB}}=tcp:0.0.0.0:{{FOREIGN_INT_PORT}}", "-credential_file=/secrets/cloudsql/credentials.json"] volumeMounts: - name: cloudsql-instance-credentials mountPath: /secrets/cloudsql readOnly: true ports: - name: {{ORDER_INT_SVC}} containerPort: {{ORDER_INT_PORT}} - name: {{SUPPLIER_INT_SVC}} containerPort: {{SUPPLIER_INT_PORT}} - name: {{CONTENT_INT_SVC}} containerPort: {{CONTENT_INT_PORT}} - name: {{CD_ORDER_INT_SVC}} containerPort: {{CD_ORDER_INT_PORT}} - name: {{SHOP_MAIN_INT_SVC}} containerPort: {{SHOP_MAIN_INT_PORT}} - name: {{FF_MASTER_INT_SVC}} containerPort: {{FF_MASTER_INT_PORT}} - name: {{FOREIGN_INT_SVC}} containerPort: {{FOREIGN_INT_PORT}} volumes: - name: cloudsql-instance-credentials secret: secretName: service-account-order-db ``` **Exception:** ```An exception occured in driver: MySQL server has gone away", Doctrine\DBAL\Driver\Mysqli\MysqliException) ``` After removing the Proxy and connecting direct to Google Cloud SQL, the connection will work properly. It seems that ```php $this->_conn = $this->_driver->connect($this->_params, $user, $password, $driverOptions); $this->_isConnected = true;` ``` does not returns the correct state (i dont know why) PHP Version: 7.1.22 Kubernetes Version 1.9.x Google Managed Kubnernetes (Autoscaled - thats why we cant use fixed IPs for DB Access) This issue is happens when you use TYPO3 CMS 8.7.19 on Google Kubernetes with SQL Proxy, install tool - Install tool: Database analyzer
admin closed this issue 2026-01-22 15:26:31 +01:00
Author
Owner

@Ocramius commented on GitHub (Oct 9, 2018):

@cccdemon what's the result of $this->_driver->connect() there?

@Ocramius commented on GitHub (Oct 9, 2018): @cccdemon what's the result of `$this->_driver->connect()` there?
Author
Owner

@cccdemon commented on GitHub (Oct 10, 2018):

@Ocramius

Uncaught TYPO3 Exception: An exception occured in driver: MySQL server has gone away |
Doctrine\\DBAL\\Exception\\DriverException thrown in file \/var\/www\/typo3_src-8.7\/vendor\/doctrine\/dbal\/lib\/Doctrine\/DBAL\/Driver\/AbstractMySQLDriver.php in line 115. 

Requested URL: http:\/\/localhost:8080\/typo3\/install.php?&install[action]=importantActions&install[controller]=tool&install[context]=standalone","correlation_id":"TYPO3-e8ea6df321cda","user_correlation_id":"TYPO3-e8ea6df321cda",
"backTrace":[{"function":"writeLogEntries","class":"TYPO3\\CMS\\Core\\Error\\AbstractExceptionHandler","file":"\/var\/www\/typo3_src-8.7\/vendor\/typo3\/cms\/typo3\/sysext\/core\/Classes\/Error\/DebugExceptionHandler.php","line":48},
{"function":"echoExceptionWeb",
"class":"TYPO3\\CMS\\Core\\Error\\DebugExceptionHandler","file":"\/var\/www\/typo3_src-8.7\/vendor\/typo3\/cms\/typo3\/sysext\/core\/Classes\/Error\/AbstractExceptionHandler.php",
"line":45},{"function":"handleException","class":"TYPO3\\CMS\\Core\\Error\\AbstractExceptionHandler",
"file":null,"line":null}]}
Doctrine\DBAL\Driver\Mysqli\MysqliConnection Object
(
    [_conn:Doctrine\DBAL\Driver\Mysqli\MysqliConnection:private] => mysqli Object
        (
            [affected_rows] => 0
            [client_info] => mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $
            [client_version] => 50012
            [connect_errno] => 0
            [connect_error] => 
            [errno] => 0
            [error] => 
            [error_list] => Array
                (
                )

            [field_count] => 0
            [host_info] => content-db via TCP/IP
            [info] => 
            [insert_id] => 0
            [server_info] => 5.7.14-google
            [server_version] => 50714
            [stat] => Uptime: 69266  Threads: 5  Questions: 116201  Slow queries: 0  Opens: 3445  Flush tables: 1  Open tables: 1126  Queries per second avg: 1.677
            [sqlstate] => 00000
            [protocol_version] => 10
            [thread_id] => 4094
            [warning_count] => 0
        )

)
MySQL server has gone away#0 /var/www/typo3_src-8.7/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php(36): Doctrine\DBAL\Driver\Mysqli\MysqliConnection->__construct(Array, 'OUR_SECRET_USER', OUR_SECRET_PW', Array)
#1 /var/www/typo3_src-8.7/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(360): Doctrine\DBAL\Driver\Mysqli\Driver->connect(Array, Array)
#2 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Database/Connection.php(96): Doctrine\DBAL\Connection->connect()
#3 /var/www/typo3_src-8.7/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(1384): TYPO3\CMS\Core\Database\Connection->connect()
#4 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Database/DatabaseConnection.php(1299): Doctrine\DBAL\Connection->getWrappedConnection()
#5 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Database/DatabaseConnection.php(1647): TYPO3\CMS\Core\Database\DatabaseConnection->sql_pconnect()
#6 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Database/DatabaseConnection.php(484): TYPO3\CMS\Core\Database\DatabaseConnection->connectDB()
#7 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Database/DatabaseConnection.php(1408): TYPO3\CMS\Core\Database\DatabaseConnection->query('SHOW TABLE STAT...')
#8 /var/www/html/typo3conf/ext/dce/Classes/Injector.php(263): TYPO3\CMS\Core\Database\DatabaseConnection->admin_get_tables()
#9 /var/www/html/typo3conf/ext/dce/Classes/Injector.php(128): ArminVieweg\Dce\Injector->getDatabaseDces()
#10 /var/www/html/typo3conf/ext/dce/ext_localconf.php(111): ArminVieweg\Dce\Injector->injectPluginConfiguration()
#11 /var/www/html/typo3conf/ext/dce/ext_localconf.php(127): TYPO3\CMS\Core\Utility\ExtensionManagementUtility::{closure}('dce')
#12 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php(1621): require('/var/www/html/t...')
#13 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php(1602): TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadSingleExtLocalconfFiles()
#14 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Core/Bootstrap.php(486): TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadExtLocalconf(false)
#15 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Classes/Controller/Action/AbstractAction.php(195): TYPO3\CMS\Core\Core\Bootstrap->loadTypo3LoadedExtAndExtLocalconf(false)
#16 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Classes/Controller/Action/Tool/ImportantActions.php(49): TYPO3\CMS\Install\Controller\Action\AbstractAction->loadExtLocalconfDatabaseAndExtTables()
#17 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Classes/Controller/Action/AbstractAction.php(68): TYPO3\CMS\Install\Controller\Action\Tool\ImportantActions->executeAction()
#18 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Classes/Controller/ToolController.php(187): TYPO3\CMS\Install\Controller\Action\AbstractAction->handle()
#19 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Classes/Controller/ToolController.php(63): TYPO3\CMS\Install\Controller\ToolController->dispatchAuthenticationActions()
#20 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Classes/Http/RequestHandler.php(63): TYPO3\CMS\Install\Controller\ToolController->execute()
#21 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Core/Bootstrap.php(316): TYPO3\CMS\Install\Http\RequestHandler->handleRequest(Object(TYPO3\CMS\Core\Http\ServerRequest))
#22 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Classes/Http/Application.php(75): TYPO3\CMS\Core\Core\Bootstrap->handleRequest(Object(TYPO3\CMS\Core\Http\ServerRequest))
#23 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Resources/Private/Php/install.php(103): TYPO3\CMS\Install\Http\Application->run()
#24 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Resources/Private/Php/install.php(104): {closure}()
#25 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/install.php(3): require('/var/www/typo3_...')
#26 {main}
@cccdemon commented on GitHub (Oct 10, 2018): @Ocramius ``` Uncaught TYPO3 Exception: An exception occured in driver: MySQL server has gone away | Doctrine\\DBAL\\Exception\\DriverException thrown in file \/var\/www\/typo3_src-8.7\/vendor\/doctrine\/dbal\/lib\/Doctrine\/DBAL\/Driver\/AbstractMySQLDriver.php in line 115. Requested URL: http:\/\/localhost:8080\/typo3\/install.php?&install[action]=importantActions&install[controller]=tool&install[context]=standalone","correlation_id":"TYPO3-e8ea6df321cda","user_correlation_id":"TYPO3-e8ea6df321cda", "backTrace":[{"function":"writeLogEntries","class":"TYPO3\\CMS\\Core\\Error\\AbstractExceptionHandler","file":"\/var\/www\/typo3_src-8.7\/vendor\/typo3\/cms\/typo3\/sysext\/core\/Classes\/Error\/DebugExceptionHandler.php","line":48}, {"function":"echoExceptionWeb", "class":"TYPO3\\CMS\\Core\\Error\\DebugExceptionHandler","file":"\/var\/www\/typo3_src-8.7\/vendor\/typo3\/cms\/typo3\/sysext\/core\/Classes\/Error\/AbstractExceptionHandler.php", "line":45},{"function":"handleException","class":"TYPO3\\CMS\\Core\\Error\\AbstractExceptionHandler", "file":null,"line":null}]} ``` ``` Doctrine\DBAL\Driver\Mysqli\MysqliConnection Object ( [_conn:Doctrine\DBAL\Driver\Mysqli\MysqliConnection:private] => mysqli Object ( [affected_rows] => 0 [client_info] => mysqlnd 5.0.12-dev - 20150407 - $Id: 38fea24f2847fa7519001be390c98ae0acafe387 $ [client_version] => 50012 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) [field_count] => 0 [host_info] => content-db via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.7.14-google [server_version] => 50714 [stat] => Uptime: 69266 Threads: 5 Questions: 116201 Slow queries: 0 Opens: 3445 Flush tables: 1 Open tables: 1126 Queries per second avg: 1.677 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 4094 [warning_count] => 0 ) ) ``` ``` MySQL server has gone away#0 /var/www/typo3_src-8.7/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php(36): Doctrine\DBAL\Driver\Mysqli\MysqliConnection->__construct(Array, 'OUR_SECRET_USER', OUR_SECRET_PW', Array) #1 /var/www/typo3_src-8.7/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(360): Doctrine\DBAL\Driver\Mysqli\Driver->connect(Array, Array) #2 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Database/Connection.php(96): Doctrine\DBAL\Connection->connect() #3 /var/www/typo3_src-8.7/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(1384): TYPO3\CMS\Core\Database\Connection->connect() #4 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Database/DatabaseConnection.php(1299): Doctrine\DBAL\Connection->getWrappedConnection() #5 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Database/DatabaseConnection.php(1647): TYPO3\CMS\Core\Database\DatabaseConnection->sql_pconnect() #6 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Database/DatabaseConnection.php(484): TYPO3\CMS\Core\Database\DatabaseConnection->connectDB() #7 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Database/DatabaseConnection.php(1408): TYPO3\CMS\Core\Database\DatabaseConnection->query('SHOW TABLE STAT...') #8 /var/www/html/typo3conf/ext/dce/Classes/Injector.php(263): TYPO3\CMS\Core\Database\DatabaseConnection->admin_get_tables() #9 /var/www/html/typo3conf/ext/dce/Classes/Injector.php(128): ArminVieweg\Dce\Injector->getDatabaseDces() #10 /var/www/html/typo3conf/ext/dce/ext_localconf.php(111): ArminVieweg\Dce\Injector->injectPluginConfiguration() #11 /var/www/html/typo3conf/ext/dce/ext_localconf.php(127): TYPO3\CMS\Core\Utility\ExtensionManagementUtility::{closure}('dce') #12 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php(1621): require('/var/www/html/t...') #13 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php(1602): TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadSingleExtLocalconfFiles() #14 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Core/Bootstrap.php(486): TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadExtLocalconf(false) #15 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Classes/Controller/Action/AbstractAction.php(195): TYPO3\CMS\Core\Core\Bootstrap->loadTypo3LoadedExtAndExtLocalconf(false) #16 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Classes/Controller/Action/Tool/ImportantActions.php(49): TYPO3\CMS\Install\Controller\Action\AbstractAction->loadExtLocalconfDatabaseAndExtTables() #17 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Classes/Controller/Action/AbstractAction.php(68): TYPO3\CMS\Install\Controller\Action\Tool\ImportantActions->executeAction() #18 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Classes/Controller/ToolController.php(187): TYPO3\CMS\Install\Controller\Action\AbstractAction->handle() #19 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Classes/Controller/ToolController.php(63): TYPO3\CMS\Install\Controller\ToolController->dispatchAuthenticationActions() #20 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Classes/Http/RequestHandler.php(63): TYPO3\CMS\Install\Controller\ToolController->execute() #21 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/core/Classes/Core/Bootstrap.php(316): TYPO3\CMS\Install\Http\RequestHandler->handleRequest(Object(TYPO3\CMS\Core\Http\ServerRequest)) #22 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Classes/Http/Application.php(75): TYPO3\CMS\Core\Core\Bootstrap->handleRequest(Object(TYPO3\CMS\Core\Http\ServerRequest)) #23 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Resources/Private/Php/install.php(103): TYPO3\CMS\Install\Http\Application->run() #24 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/sysext/install/Resources/Private/Php/install.php(104): {closure}() #25 /var/www/typo3_src-8.7/vendor/typo3/cms/typo3/install.php(3): require('/var/www/typo3_...') #26 {main} ```
Author
Owner

@cccdemon commented on GitHub (Oct 10, 2018):

In my tests i figured out that:

        if ( ! $this->_conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags)) {

because of the "$flags"
$flags value = 2112 (duno what it means yet - but i will figure it out)

@cccdemon commented on GitHub (Oct 10, 2018): In my tests i figured out that: ``` if ( ! $this->_conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags)) { ``` because of the "$flags" $flags value = 2112 (duno what it means yet - but i will figure it out)
Author
Owner

@cccdemon commented on GitHub (Oct 10, 2018):

Well.

this is a Patch, made by our Developers. The are using
'flags' => MYSQLI_CLIENT_SSL | MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT,

This is NOT working with google kubernetes Cloud SQL Proxy!!!

So this is not a Bug on Doctrine.
Issue Closed

@cccdemon commented on GitHub (Oct 10, 2018): Well. this is a Patch, made by our Developers. The are using ``` 'flags' => MYSQLI_CLIENT_SSL | MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT, ``` This is NOT working with google kubernetes Cloud SQL Proxy!!! So this is not a Bug on Doctrine. Issue Closed
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6082