{"record":{"id":"e003eab13aeaf55d","repo":"phacility/phabricator","slug":"attempt-to-connect-to-s-s-failed-with-error-d","errorCode":null,"errorMessage":"Attempt to connect to %s@%s failed with error #%d: %s.","messagePattern":"Attempt to connect to (.+?)@(.+?) failed with error #(.+?): (.+?)\\.","errorType":"exception","errorClass":"AphrontConnectionQueryException","httpStatus":null,"severity":"error","filePath":"src/infrastructure/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php","lineNumber":384,"sourceCode":"        throw new AphrontSchemaQueryException($message);\n    }\n\n    // TODO: 1064 is syntax error, and quite terrible in production.\n\n    return null;\n  }\n\n  protected function throwConnectionException($errno, $error, $user, $host) {\n    $this->throwCommonException($errno, $error);\n\n    $message = pht(\n      'Attempt to connect to %s@%s failed with error #%d: %s.',\n      $user,\n      $host,\n      $errno,\n      $error);\n\n    throw new AphrontConnectionQueryException($message, $errno);\n  }\n\n\n  protected function throwQueryCodeException($errno, $error) {\n    $this->throwCommonException($errno, $error);\n\n    $message = pht(\n      '#%d: %s',\n      $errno,\n      $error);\n\n    throw new AphrontQueryException($message, $errno);\n  }\n\n  /**\n   * Force the next query to fail with a simulated error. This should be used\n   * ONLY for unit tests.\n   */","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/infrastructure/storage/connection/mysql/AphrontBaseMySQLDatabaseConnection.php#L366-L402","documentation":"Thrown by throwConnectionException() when opening a connection fails with an errno that throwCommonException() does not classify into a more specific exception. It wraps the raw error as AphrontConnectionQueryException, e.g. 2002/2003 'Can't connect to MySQL server', name-resolution failures, or 'too many connections' (1040). The $errno of the underlying failure is attached to the exception.","triggerScenarios":"Any connection attempt while mysqld is stopped, restarting, or unreachable; wrong mysql.host / mysql.port in configuration; firewall, DNS, or container-network failure between the web host and the database; hitting max_connections so the server refuses new links.","commonSituations":"MySQL crashed or was restarted during a deploy; config still points at a decommissioned host; Docker/Kubernetes networking rules blocking the port; connection storms from daemons exhausting max_connections; transient cloud/network blips.","solutions":["Confirm the server is reachable from the Phabricator host exactly as configured: mysql -h<host> -P<port> -u<user> -p","Fix mysql.host/mysql.port (or cluster.databases) if they point at the wrong place","If MySQL refuses with too many connections, raise max_connections and find the connection leak","Treat as transient where appropriate: this is a connect-phase failure, so a retry with backoff after the server returns is safe"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Optional liveness probe before dispatching work:\n$conn = $dao->establishConnection('r');\nqueryfx($conn, 'SELECT 1');","typeGuard":null,"tryCatchPattern":"$attempts = 3;\ndo {\n  try {\n    $conn = $dao->establishConnection('r');\n    break;\n  } catch (AphrontConnectionQueryException $ex) {\n    // Connect-phase failure: transient by nature. Back off, then retry;\n    // give up after N attempts and degrade to an availability error.\n    if (--$attempts <= 0) {\n      throw $ex;\n    }\n    sleep(pow(2, 3 - $attempts));\n  }\n} while (true);","preventionTips":["Monitor mysqld availability and alert before connection storms cascade","Keep mysql.host/mysql.port (or cluster.databases) accurate through infrastructure changes","Size max_connections for daemons + web workers so the server never refuses links","Wrap non-critical read paths to degrade gracefully when the database is briefly unreachable"],"tags":["mysql","connection","network","configuration","availability"],"backgroundTag":"database-connection-failed","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}