Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIGSEGV with Coroutine::getaddrinfo #5547

Closed
deba12 opened this issue Oct 26, 2024 · 4 comments
Closed

SIGSEGV with Coroutine::getaddrinfo #5547

deba12 opened this issue Oct 26, 2024 · 4 comments

Comments

@deba12
Copy link

deba12 commented Oct 26, 2024

Please answer these questions before submitting your issue.

  1. What did you do? If possible, provide a simple script for reproducing the error.
    SIGSEGV with Coroutine::getaddrinfo
<?php
declare(strict_types=1);

use Swoole\Coroutine;

Coroutine::set(['hook_flags' => SWOOLE_HOOK_ALL]);

go(static function () {


    $res = Coroutine::getaddrinfo(
        domain: 'swoole-non-existent-domain',
        protocol: 0,
        service: '',
        timeout: 5,
    );

    var_dump($res);
});
  1. What did you expect to see?
bool(false)
  1. What did you see instead?
$ php cli/dns-bug.php
bool(false)
Segmentation fault
  • backtrace from gdb
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7fffee7016c0 (LWP 7705)]
[New Thread 0x7fffedf006c0 (LWP 7706)]
[New Thread 0x7fffed6ff6c0 (LWP 7707)]
[New Thread 0x7fffecefe6c0 (LWP 7708)]
[New Thread 0x7fffdffff6c0 (LWP 7709)]
[New Thread 0x7fffdf7fe6c0 (LWP 7710)]
[New Thread 0x7fffdeffd6c0 (LWP 7711)]
[New Thread 0x7fffde7fc6c0 (LWP 7712)]
[New Thread 0x7fffddffb6c0 (LWP 7713)]
[New Thread 0x7fffdd7fa6c0 (LWP 7714)]
[New Thread 0x7fffdcff96c0 (LWP 7715)]
[New Thread 0x7fffbbfff6c0 (LWP 7716)]
[New Thread 0x7fffbb7fe6c0 (LWP 7717)]
[New Thread 0x7fffbaffd6c0 (LWP 7718)]
[New Thread 0x7fffba7fc6c0 (LWP 7719)]
[New Thread 0x7fffb9ffb6c0 (LWP 7720)]
bool(false)

Thread 2 "php" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffee7016c0 (LWP 7705)]
swoole::network::getaddrinfo (req=req@entry=0x7fffee901980) at ./build-8.3/src/network/dns.cc:772
772     ./build-8.3/src/network/dns.cc: No such file or directory.
(gdb) bt full
#0  swoole::network::getaddrinfo (req=req@entry=0x7fffee901980) at ./build-8.3/src/network/dns.cc:772
        result = 0x0
        ptr = 0x0
        hints = {ai_flags = 0, ai_family = 2, ai_socktype = 1, ai_protocol = 0, ai_addrlen = 0, ai_addr = 0x0, ai_canonname = 0x0, ai_next = 0x0}
        ret = -3
        buffer = <optimized out>
        i = <optimized out>
        __PRETTY_FUNCTION__ = "int swoole::network::getaddrinfo(GetaddrinfoRequest*)"
#1  0x00007fffef04e0b5 in swoole::async::handler_getaddrinfo (event=0x555555ef26b0) at ./build-8.3/src/os/base.cc:108
        req = 0x7fffee901980
#2  0x00007fffef04bee5 in operator() (__closure=0x555555bca1b8) at ./build-8.3/src/os/async_thread.cc:251
        event = 0x555555ef26b0
        exit_flag = false
        ext_exitBlock_229 = {_fun = {<No data fields>}, _active = true}
        is_core_worker = true
        this = 0x555555f69ba0
        _send_event = <optimized out>
        is_core_worker = <optimized out>
        this = <optimized out>
        __PRETTY_FUNCTION__ = <optimized out>
        exit_flag = <optimized out>
        ext_exitBlock_229 = <optimized out>
        event = <optimized out>
        ret = <optimized out>
        _sw_error_len = <optimized out>
        lock = <optimized out>
#3  std::__invoke_impl<void, swoole::async::ThreadPool::create_thread(bool)::<lambda()> > (__f=...) at /usr/include/c++/12/bits/invoke.h:61
No locals.
#4  std::__invoke<swoole::async::ThreadPool::create_thread(bool)::<lambda()> > (__fn=...) at /usr/include/c++/12/bits/invoke.h:96
No locals.
#5  std::thread::_Invoker<std::tuple<swoole::async::ThreadPool::create_thread(bool)::<lambda()> > >::_M_invoke<0> (this=0x555555bca1b8) at /usr/include/c++/12/bits/std_thread.h:252
No locals.
#6  std::thread::_Invoker<std::tuple<swoole::async::ThreadPool::create_thread(bool)::<lambda()> > >::operator() (this=0x555555bca1b8) at /usr/include/c++/12/bits/std_thread.h:259
No locals.
#7  std::thread::_State_impl<std::thread::_Invoker<std::tuple<swoole::async::ThreadPool::create_thread(bool)::<lambda()> > > >::_M_run(void) (this=0x555555bca1b0) at /usr/include/c++/12/bits/std_thread.h:210
No locals.
#8  0x00007ffff53b64a3 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
No symbol table info available.
#9  0x00007ffff758b144 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
        ret = <optimized out>
        pd = <optimized out>
        out = <optimized out>
        unwind_buf = {cancel_jmp_buf = {{jmp_buf = {140737193711296, 2123964537826586669, -696, 0, 140737195808208, 140737185320960, -2123998498760282067, -2123947711764090835}, mask_was_saved = 0}}, priv = {
            pad = {0x0, 0x0, 0x0, 0x0}, data = {prev = 0x0, cleanup = 0x0, canceltype = 0}}}
        not_first_call = <optimized out>
#10 0x00007ffff760b7dc in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81
No locals.
  1. What version of Swoole are you using (show your php --ri swoole)?

swoole

Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 5.1.4
Built => Sep 21 2024 05:43:29
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 3.0.14 4 Jun 2024
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
c-ares => 1.18.1
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
async_redis => enabled
coroutine_pgsql => enabled
coroutine_sqlite => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_fiber_mock => Off => Off
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?
Linux e1 5.15.153.1-microsoft-standard-WSL2 #1 SMP Fri Mar 29 23:14:13 UTC 2024 x86_64 GNU/Linux
PHP 8.3.11 (cli) (built: Sep  2 2024 15:06:27) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.11, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.11, Copyright (c), by Zend Technologies
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 12.2.0-14' --with-bugurl=file:///usr/share/doc/gcc-12/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-12 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-12-bTRWOB/gcc-12-12.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-12-bTRWOB/gcc-12-12.2.0/debian/tmp-gcn/usr --enable-offload-defaulted --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Debian 12.2.0-14)
@matyhtf
Copy link
Member

matyhtf commented Oct 29, 2024

无法重现

微信截图_20241029135221

出现这个问题,一般是主进程已退出了,但是 AIO 线程依然在运行。你提供的代码是否完整,或者是否安装了什么特殊的扩展。

建议使用 valgrind 跟踪内存错误

@deba12
Copy link
Author

deba12 commented Oct 29, 2024

valgrind.txt

@deba12
Copy link
Author

deba12 commented Oct 29, 2024

@matyhtf could you please make backport for 5.1.x ?

@matyhtf
Copy link
Member

matyhtf commented Oct 30, 2024

@deba12 This fix will be included in version 5.1.6.

NathanFreeman added a commit to NathanFreeman/swoole-src that referenced this issue Nov 24, 2024
NathanFreeman added a commit to NathanFreeman/swoole-src that referenced this issue Nov 24, 2024
matyhtf pushed a commit that referenced this issue Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants