php / php/php-src

Connecting to PDO / MySQL database over unix-socket throws "a retry" error

Open
#22,981 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: pdo_mysql Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

<?php

Resulted in this output:

Error message: SQLSTATE[HY000] [2002] Resource temporarily unavailable

Error stack trace:

#0 /location-to-php.php(43): PDO->__construct()
#xx: our code

But I expected this output instead:

No crash.

This is a bug in mysqlnd in that it returns a "2002" error code (I looked into the code -- it's a "try again" code, that is a look / backoff should be taken). This happens when connecting to MySQL using a unix socket. And it happens when a high-frequency of calls are made in short succession.

Ideally a unix-socket should be opened once per process and all communication should happen on that socket (rather than opening and closing it over and over again). And "retry" "errors" (not an error) should be handled correctly.

I haven't dug into the mysqlnd extension into how to fix this yet. If someone wants to jump on this first, that would be appreciated. Otherwise I'll dig into it next week.

PHP Version
8.5.9
Operating System

Debian 12

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The reported entry point is PDO->__construct() when connecting to MySQL through a Unix socket; the relevant subsystem is the mysqlnd extension. Start by reproducing the high-frequency connection sequence on PHP 8.5.9 and Debian 12, then inspect how socket retries are handled; done means the sequence no longer returns SQLSTATE[HY000] [2002] Resource temporarily unavailable.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, php
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.