{"record":{"id":"46c617acf517c69e","repo":"phacility/phabricator","slug":"2006","errorCode":"2006","errorMessage":"#%d: %s\n\nThis error may occur if your configured MySQL \"wait_timeout\" or \"max_allowed_packet\" values are too small. This may also indicate that something used the MySQL \"KILL <process>\" command to kill the connection running the query.","messagePattern":"#(.+?): (.+?)\n\nThis error may occur if your configured MySQL \"wait_timeout\" or \"max_allowed_packet\" values are too small\\. This may also indicate that something used the MySQL \"KILL <process>\" command to kill the connection running the query\\.","errorType":"exception","errorClass":"AphrontConnectionLostQueryException","httpStatus":null,"severity":"error","filePath":"src/infrastructure/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php","lineNumber":336,"sourceCode":"      $errno = $this->getErrorCode($connection);\n      $error = $this->getErrorDescription($connection);\n    }\n    $this->throwQueryCodeException($errno, $error);\n  }\n\n  private function throwCommonException($errno, $error) {\n    $message = pht('#%d: %s', $errno, $error);\n\n    switch ($errno) {\n      case 2013: // Connection Dropped\n        throw new AphrontConnectionLostQueryException($message);\n      case 2006: // Gone Away\n        $more = pht(\n          'This error may occur if your configured MySQL \"wait_timeout\" or '.\n          '\"max_allowed_packet\" values are too small. This may also indicate '.\n          'that something used the MySQL \"KILL <process>\" command to kill '.\n          'the connection running the query.');\n        throw new AphrontConnectionLostQueryException(\"{$message}\\n\\n{$more}\");\n      case 1213: // Deadlock\n        throw new AphrontDeadlockQueryException($message);\n      case 1205: // Lock wait timeout exceeded\n        throw new AphrontLockTimeoutQueryException($message);\n      case 1062: // Duplicate Key\n        // NOTE: In some versions of MySQL we get a key name back here, but\n        // older versions just give us a key index (\"key 2\") so it's not\n        // portable to parse the key out of the error and attach it to the\n        // exception.\n        throw new AphrontDuplicateKeyQueryException($message);\n      case 1044: // Access denied to database\n      case 1142: // Access denied to table\n      case 1143: // Access denied to column\n      case 1227: // Access denied (e.g., no SUPER for SHOW SLAVE STATUS).\n\n        // See T13622. Try to help users figure out that this is a GRANT\n        // problem.\n","sourceCodeStart":318,"sourceCodeEnd":354,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/infrastructure/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php#L318-L354","documentation":"MySQL errno 2006 'MySQL server has gone away', translated by throwCommonException() into AphrontConnectionLostQueryException with appended guidance. 'Gone away' specifically means the client's connection was already dead when it tried to use it: exceeded wait_timeout, a packet larger than max_allowed_packet (either direction), the server killing the connection (KILL, OOM, restart), or a network device dropping the session.","triggerScenarios":"A daemon holds a connection idle longer than the server's wait_timeout, then issues a query; writing a blob larger than max_allowed_packet; an operator or monitoring system running KILL on long queries; mysqld restarted or was OOM-killed.","commonSituations":"Phabricator daemons idle overnight between task bursts; large file/repository metadata writes exceeding the default 16MB max_allowed_packet; aggressive connectionkillers in managed MySQL.","solutions":["Retry the operation — Phabricator's worker infrastructure retries connection-lost exceptions automatically, so single occurrences are usually self-healing","Raise max_allowed_packet on the server (and client) if large payloads trigger it","Raise wait_timeout (or keep connections busy) if idle daemons are being cut off","Check mysqld logs / audit who issued KILL if the message appears during normal packet sizes"],"exampleFix":"# before (my.cnf)\nmax_allowed_packet = 16M\nwait_timeout = 60\n\n# after\nmax_allowed_packet = 64M\nwait_timeout = 600\n# then restart mysqld; retry the failed operation","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  $rows = queryfx_all($conn, $sql);\n} catch (AphrontConnectionLostQueryException $ex) {\n  if (preg_match('/^#2006:/', $ex->getMessage())) {\n    // gone away: fresh connection, then retry once\n    $conn = $object->establishConnection('r');\n    $rows = queryfx_all($conn, $sql);\n  } else {\n    throw $ex;\n  }\n}","preventionTips":["Set max_allowed_packet (server and client) above your largest payload","Set wait_timeout above your daemons' longest idle gap, or schedule periodic keepalive queries","If a monitoring system kills long queries, exclude Phabricator's legitimate long-running reports/exports"],"tags":["database","mysql","connection-lost","timeout","phabricator"],"backgroundTag":"mysql-server-gone-away","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}