openswoole / ext-openswoole

Programmatic server for PHP with async IO, coroutines and fibers
https://openswoole.com
Apache License 2.0
808 stars 51 forks source link

Segmentation fault (core dumped) while using `Server::tick()` or `Timer::tick()` with `Server::stats()` #325

Closed megasteve19 closed 1 year ago

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

I came up this error everytime, I'm not sure why.

<?php

use OpenSwoole\Server;
use OpenSwoole\Timer;

$server = new Server('0.0.0.0', 9500);

// $server->tick(2000, function() use ($server) {
//  print_r($server->stats());
// });

Timer::tick(2000, function() use ($server) {
    print_r($server->stats());
});

$server->on('Receive', function(Server $server, $socket, $fromId, $data) {
    print_r($data);
});

$server->start();

Output is:

$ php server.php 
Segmentation fault (core dumped)
2. What did you expect to see?

Stats of the server every 2 seconds.

3. What did you see instead?

For our production code, I just added dirty way of connecting to server saving stats to the database and closing connection. Cron is the responsible instead of OpenSwoole's timer.

4. What version of OpenSwoole are you using (show your `php --ri openswoole`)?

22.0.0

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

It's not about the my own computer it's common for every machine: Linux fedora 6.4.11-200.fc38.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Aug 16 17:42:12 UTC 2023 x86_64 GNU/Linux

PHP 8.2.9 (cli) (built: Aug  3 2023 11:39:08) (NTS gcc x86_64)
Copyright (c) The PHP Group
Zend Engine v4.2.9, Copyright (c) Zend Technologies
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/13/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,objc,obj-c++,ada,go,d,m2,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-libstdcxx-backtrace --with-libstdcxx-zoneinfo=/usr/share/zoneinfo --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-13.2.1-20230728/obj-x86_64-redhat-linux/isl-install --enable-offload-targets=nvptx-none --without-cuda-driver --enable-offload-defaulted --enable-gnu-indirect-function --enable-cet --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux --with-build-config=bootstrap-lto --enable-link-serialization=1
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.1 20230728 (Red Hat 13.2.1-1) (GCC) 
doubaokun commented 1 year ago

Use this function https://openswoole.com/docs/modules/swoole-server-tick