Oh, and does this mean Laravel only auto-reconnects database connections in English locales? Is everyone outside US/UK just hacking a workaround of some sort?
How do I add a message to the list detecting a closed database connection?
So, I'm using long-running queue workers and an Azure SQL Server database. On the whole it works great, except for when the workers have not processed a job in some time.
What happens is the database connection drops after some time unused, as you would expect, but Laravel does not detect this. Instead it blindly keeps trying to use the dead database connection for every new job that is dispatched.
Azure SQL Server PDO returns this error when the connection times out:
ERROR: SQLSTATE[08S02]: [Microsoft][ODBC Driver 13 for SQL Server]SMux Provider: Physical connection is not usable [xFFFFFFFF].
It seems that Laravel detects a database connection has been lost by comparing this message with a list of messages (all in English!) that it holds here in Illuminate\Database\DetectsLostConnections:
protected function causedByLostConnection(Throwable $e)
{
$message = $e->getMessage();
return Str::contains($message, [
'server has gone away',
'no connection to the server',
'Lost connection',
'is dead or not enabled',
'Error while sending',
'decryption failed or bad record mac',
'server closed the connection unexpectedly',
'SSL connection has been closed unexpectedly',
'Error writing data to the connection',
'Resource deadlock avoided',
'Transaction() on null',
'child connection forced to terminate due to client_idle_limit',
'query_wait_timeout',
'reset by peer',
]);
}
So here is my quandary: how do I fix this? If I add the Azure message "Physical connection is not usable" to this list, then my long-running jobs have a happy time. I can submit this as a PR, so other people's long-running jobs can be in the happy place too. But what do I do in the meantime? What do I need to configure/inject/extend/whatever to get more messages into this array? Overriding that one script in the autoloader is one way, but it's not very update-safe.
Thanks.
Please or to participate in this conversation.