7

At the startup of the docker application (with laravel php), for 1 request, connection to database is fine. After the first request I start to get this error.

SQLSTATE[08006] [7] could not send SSL negotiation packet: Resource temporarily unavailable (Connection: pgsql, SQL: (select * from ........)

Using:

  • Laravel v10 and above.
  • PHP 8.3 and above
  • Docker with Ubuntu Latest

I tracked down this problem until I found out that PDO is actually not openning a connection to PostgreSQL. I tested it with iptraf and both pg_connect and PDO. When we use PDO, we get the error above and but when I try to use pg_connect, we can connect and even make a query.

So my findings are, when using iptraf

  • Cannot open a connection using PDO
  • IPTraf does not show connection openned with PDO
  • I can open a connection using pg_connect
  • I can open a connection from a database manager application
  • Happening on both development and production environments

[EDIT] New findings:

  • The whole setup is working on a virtual machine rather then a docker.
5
  • 2
    SQL state 08006 is a connection_failure. When using only PostgreSQL, I would always use the native PostgreSQL functions in PHP, not PDO. This will fix your problem, gives you more functionality and a better performance. Commented Jun 25 at 21:26
  • 1
    This is a horrible comment as Laravel requires the use of PDO in its database connections and ORM. Saying "Just don't use PDO is not the 'fix your problem'"
    – gofish
    Commented Jun 26 at 1:28
  • @Frank Yes its a connection failure, as I stated. And unfortunately this is a 1 year old project with a lot of developers, cant start from the begining. Commented Jun 26 at 3:44
  • Did you try without SSL?
    – Olivier
    Commented Jun 26 at 7:00
  • Yes I did try. When I try without SSL it converts to a socket issue. Commented Jun 27 at 16:32

9 Answers 9

8

Check the php-swoole package version on your failed deployment. If it is 6.0.0 probably you have here the problem.

Edit: We also have this problem, we deployed a container compiled from last week and one with the same code but compiled this week, the difference was that the swoole package had been updated from version 5x to 6.0.0, which is an alpha version. Mysteriously, this version has sneaked into the Ubuntu repository, not being recommended for production and its changelog indicates several changes and incompatibilities with PDO.

From php pecl

  • No longer supports Swoole\Coroutine\PostgreSQL coroutine client.
  • Swoole-v6.0.0-alpha is a test version and cannot be used in any production environment; it is for testing purposes only.

HOW TO SOLVE IT: Remove swoole if you don't need it. If you need it, right now the previous version is not listed on the repo, so you need to get it alternatively.

6
  • OMG! I removed Swoole and everything started to work fine. What is the problem with that ? Commented Jun 27 at 14:52
  • It worked man! awesome. Thanks. Commented Jun 27 at 16:31
  • Well, we also have this problem, We deployed a container compiled from last week and one with the same code but compiled this week, the difference was that the swoole package had been updated from version 5x to 6.0.0, which is an alpha version. Mysteriously, this version has sneaked into the Ubuntu repository, not being recommended for production and its changelog indicates several changes and incompatibilities with PDO.
    – alibeam
    Commented Jun 27 at 19:42
  • Edit with some more info, I haven't so much more than this.
    – alibeam
    Commented Jun 27 at 19:54
  • How do I remove that package from the project? Is it on project level, or OS level? Commented Jun 28 at 18:47
6

I'll add my 2 cents here. We were using

  • PHP 8.2.20
  • Swoole extension (v5) enabled
  • DigitalOcean PostgreSQL Database (v16)
  • Image from official (php:8.2-cli-alpine)
  • Using PDO to connect.

We had similar issues with this two types of errors:

  • with SSL disabled:
    SQLSTATE[08006] [7] could not send SSL negotiation packet: Resource temporarily unavailable
  • With SSL enabled:
    PDOException: SQLSTATE[08006] [7] could not send SSL negotiation packet: Resource temporarily unavailable

Removing the extension did the trick for us.

2
2

I want to add some clarifying information as my client and I experience the exact same issue starting after unattended-upgrades updated our PHP installation from PHP 8.2.19 to PHP 8.2.20

We have been able to conclude the following

  • PHP 8.1.x is completely unaffected by this issue. We created a temporary php script that connected to the Digital Ocean PostgreSQL database and PHP 8.1 was successfully able to connect
  • PHP 8.2.20 on Ubuntu 22.04 LTS is affected by this issue. The same script that is described above did not work with PHP 8.2.20
  • The issue was not able to be replicated using the exact same PHP installation in Amazon against RDS
  • The issue was not replicated on PHP 8.2.20 on a Laravel Herd Windows installation connecting to Digital Ocean PostgreSQL
  • The issue was replicated using Digital Ocean PostgreSQL 13, 14, 15, and 16 in Digital Ocean
  • Using a fresh Laravel installation against the Digital Ocean PostgreSQL instance we ran php8.2 artisan db and successfully were dropped a shell into PostgreSQL
  • We noted there were SSL changes within PHP 8.2.20, but do not know if these are correlated
3
  • I will try to check this and return back to you as soon as possible. Commented Jun 26 at 3:46
  • 1
    Turns out that we are also using PHP 8.2.20 at the moment. But we were already using it while it was working correct also. Just an additional information; I tried to use php8.3 also, it had the same issue. Commented Jun 26 at 3:56
  • I tried to install the application into a virtual machine and it worked without any problems. I changed the ubuntu version to 20.04 in docker, had the same error. Commented Jun 26 at 4:42
2

I was running my app with octane and swoole and had the same issue, changed it to Fraken Php and it worked. aparently Swoole updated to 6.0.0 removing support for a PDO library. i will be keeping an eye, because frankenphp perfomance is not that great compared to Swoole, but it does de same job perfectly!, thanks to all who commented and @Harun for pointing at this bug so quickly

0
1

I'll also add my 1.5 cents here. We were using:

  • PHP 8.3.8
  • DigitalOcean PostgreSQL Database (v16)
  • Swoole extension 5.1.3 enabled
  • Using PDO to connect.

We had similar issues with this two types of errors:

  • with SSL disabled:
SQLSTATE[08006] [7] could not send SSL negotiation packet: Resource temporarily unavailable
  • with SSL enabled:
PDOException: SQLSTATE[08006] [7] could not send SSL negotiation packet: Resource temporarily unavailable

Replacing swoole extension from 5.1.3 to 5.1.2 version resolved this problem.

New contributor
Novokrest is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0

For my sail docker image, I did the following:

  1. Delete the line with the installation of php8.3-swole using apt-get install
  2. Add these lines
RUN pecl install swoole-5.1.2 \
&& echo "extension=swoole.so" > /etc/php/8.3/cli/conf.d/20-swoole.ini

These lines will install swoole version 5.1.2 which still has PDO support.

  1. Rebuild your image

I use sail in my work, so I just did these actions in my dockerfile. If you are building laravel through docker, then this should help you too. If you don't use docker, then just delete/change the version of swoole via pecl as I showed above. This should help

1
  • Thank you, I was also searching for how to roll back a specific package. This can be a solution to that. Commented Jun 29 at 6:09
0

This issue also occurs on Alpine on versions of Swoole starting with 5.1.1

You may install an older version of Swoole on Alpine like this (this one works for me):

RUN apk --no-cache add php82-pecl-swoole=5.0.3-r0 --repository=http://dl-cdn.alpinelinux.org/alpine/v3.18/community

Hope this helps someone

0

If the package mysteriously sneaked into your built Docker image before, it might have been installed in your base images using PPA from deb.sury.org (ppa:ondrej/php).

Version 6.0.0 was built and distributed earlier this week. The maintainer has now re-released the stable version (see https://github.com/oerdnj/deb.sury.org/issues/2152), so try rebuilding your Docker image, and it might now use the stable version (5.1.3) of php-swoole.

0

We had the same issue. Solved by removing the php8.3-swoole extension from our PHP installation:

sudo rm /etc/php/8.3/mods-available/swoole.ini
sudo rm /etc/php/8.3/cli/conf.d/25-swoole.ini
sudo rm /etc/php/8.3/fpm/conf.d/25-swoole.ini
sudo systemctl restart php8.3-fpm

Now the application can connect to the database with no errors.

Not the answer you're looking for? Browse other questions tagged or ask your own question.