swoole-src icon indicating copy to clipboard operation
swoole-src copied to clipboard

php pdo Connection PHP Notice: PDO::__construct(): Send of 4 bytes failed with errno=32 Broken pipe in Connector.php on line 107

Open WebSMD opened this issue 3 years ago • 6 comments

Please answer these questions before submitting your issue. Thanks!

  1. What did you do? If possible, provide a simple script for reproducing the error.

new PDO($dsn, $username, $password, $options);

  1. What did you expect to see?

mysql pdo Connection

  1. What did you see instead? WARNING check_worker_exit_status: worker#5[pid=1464] abnormal exit, status=0, signal=11 PHP Notice: PDO::__construct(): Send of 4 bytes failed with errno=32 Broken pipe in

  2. What version of Swoole are you using (show your php --ri swoole)?

Swoole => enabled Author => Swoole Team [email protected] Version => 4.6.7 Built => Jun 24 2021 10:30:51 coroutine => enabled with boost asm context kqueue => enabled rwlock => enabled openssl => OpenSSL 1.1.1k 25 Mar 2021 dtls => enabled http2 => enabled curl-native => enabled pcre => enabled zlib => 1.2.11 brotli => E16777225/D16777225 async_redis => enabled

Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => Off => Off swoole.unixsock_buffer_size => 262144 => 262144

  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?

uname -a Darwin Molng.local 19.6.0 Darwin Kernel Version 19.6.0: Thu May 6 00:48:39 PDT 2021; root:xnu-6153.141.33~1/RELEASE_X86_64 x86_64 php -v PHP 7.4.20 (cli) (built: Jun 24 2021 10:03:52) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies gcc -v Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/usr/include/c++/4.2.1 Apple clang version 12.0.0 (clang-1200.0.32.29) Target: x86_64-apple-darwin19.6.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin

WebSMD avatar Jun 30 '21 05:06 WebSMD

Please use valgrind to track memory errors and submit the log here

USE_ZEND_ALLOC=0 valgrind --log-file=/tmp/valgrind.log php your_file.php

matyhtf avatar Jun 30 '21 09:06 matyhtf

这个问题我这边也碰到过,不过我这是 释放 PDO 的时候报错,我增加了一次重试

https://github.com/hyperf/hyperf/pull/3758

limingxinleo avatar Jun 30 '21 14:06 limingxinleo

遇到同样的问题,连接PDO后,在server端主动kill掉连接,触发重连时,用同样的参数初始化PDO worker就挂掉了 WARNING check_worker_exit_status: worker#1[pid=21778] abnormal exit, status=0, signal=11

A bug occurred in Swoole-v4.6.7

OS: MacOs Mojave 10.14.6

Swoole => enabled Author => Swoole Team [email protected] Version => 4.6.7 Built => Jul 10 2021 20:37:24 coroutine => enabled with boost asm context kqueue => enabled rwlock => enabled openssl => OpenSSL 1.1.1k 25 Mar 2021 dtls => enabled http2 => enabled pcre => enabled zlib => 1.2.11 brotli => E16777223/D16777223 async_redis => enabled

Directive => Local Value => Master Value swoole.enable_coroutine => On => On swoole.enable_library => On => On swoole.enable_preemptive_scheduler => Off => Off swoole.display_errors => On => On swoole.use_shortname => Off => Off swoole.unixsock_buffer_size => 262144 => 262144

Darwin MacBook-Pro-3.local 18.7.0 Darwin Kernel Version 18.7.0: Mon May 3 20:41:19 PDT 2021; root:xnu-4903.278.68~1/RELEASE_X86_64 x86_64

PHP 7.4.21 (cli) (built: Jul 1 2021 23:02:54) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.21, Copyright (c), by Zend Technologies

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1 Apple clang version 11.0.0 (clang-1100.0.33.17) Target: x86_64-apple-darwin18.7.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

ppanphper avatar Jul 11 '21 17:07 ppanphper

发现是Darwin系统下才会出现这个问题,在linux上没复现

ppanphper avatar Jul 15 '21 11:07 ppanphper

找到了100%复现方法,Linux和MacOS都可以。首先要重启MySQL,然后确保第一次连接用以下代码

<?php
use function Swoole\Coroutine\run;
use function Swoole\Coroutine\go;

run(function () {
    go(function () {
        try {
            $mysql = new mysqli('localhost', 'user', 'password', 'database');
            $mysql->close();
            echo 'Connection is established!' . PHP_EOL;
        } catch (Exception $e) {
            echo 'Cannot connect to MySQL server!' . PHP_EOL;
            echo 'Exception: ' . $e->getMessage() . PHP_EOL;
        }
    });
});

Linux上会显示

PHP Notice:  mysqli::__construct(): Send of 4 bytes failed with errno=32 Broken pipe in /root/reproduce.php on line 8
Cannot connect to MySQL server!
Exception: MySQL server has gone away

MacOS上会显示

Cannot connect to MySQL server!
Exception: No such file or directory

会一直抛这个错误,直到有一个正常的连接建立,比如用以下代码:

<?php
try {
    $mysql = new mysqli('localhost', 'user', 'password', 'database');
    $mysql->close();
    echo 'Connection is established!' . PHP_EOL;
} catch (Exception $e) {
    echo 'Cannot connect to MySQL server!' . PHP_EOL;
    echo 'Exception: ' . $e->getMessage() . PHP_EOL;
}

在这之后用第一段代码也可以连接了。

MySQL版本:8.0.28

ttc0419 avatar Mar 08 '22 16:03 ttc0419

貌似是 mysql 8.0 的 socket 问题?mysql 5.7 升级到 8.0 后出现 (hyperf),mysql 地址用 127.0.0.1 解决。

gbabook avatar Jun 12 '23 16:06 gbabook