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

Worker freezes after restart when using worker_max_concurrency #5430

Closed
allsilaevex opened this issue Aug 2, 2024 · 2 comments
Closed

Worker freezes after restart when using worker_max_concurrency #5430

allsilaevex opened this issue Aug 2, 2024 · 2 comments

Comments

@allsilaevex
Copy link

Please answer these questions before submitting your issue.

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

To reproduce the problem you need to run php server.php & php client.php and wait about 5 seconds

server.php

<?php

$server = new Swoole\Http\Server('0.0.0.0', 9999);

$server->set([
    'worker_num' => 2,
    'max_connection' => 128,
    'worker_max_concurrency' => 8, // this is the reason for bug
]);

$server->on('WorkerStart', static function (Swoole\Http\Server $server, int $workerId) {
    if ($workerId == 0) {
        Swoole\Timer::after(2000, static function () use ($server) {
            $server->stop(1);
        });
    }
});

$server->on('Request', static function (Swoole\Http\Request $request, Swoole\Http\Response $response) {
    \Swoole\Coroutine::sleep(seconds: rand(50, 100) / 1000);
    $response->end();
});

$server->start();

client.php

<?php

declare(strict_types=1);

$callback = static function () {
    Swoole\Coroutine\run(static function () {
        while (true) {
            Swoole\Coroutine::sleep(rand(15, 35) / 100.0);

            $request = static function () {
                try {
                    $response = Swoole\Coroutine\Http\get(url: 'http://0.0.0.0:9999/', options: ['timeout' => 5.0]);
                } catch (Throwable $exception) {
                    echo '[error] error: ' . $exception->getMessage() . PHP_EOL;
                    return;
                }

                if ($response->getStatusCode() > 299) {
                    echo '[error] status code = ' . $response->getStatusCode() . PHP_EOL;
                }
            };

            for ($i = 1; $i <= 5; $i++) {
                Swoole\Coroutine\go($request);
            }
        }
    });
};

for ($n = 1; $n <= 8; $n++) {
    $process = new Swoole\Process($callback);
    $process->start();
}

for ($n = 8; $n--;) {
    $status = Swoole\Process::wait();
}
  1. What did you expect to see?

0 errors

  1. What did you see instead?

error messages like:

WARNING Server::accept_connection() (ERRNO 9002): Too many connections [now: 128]
[error] error: Connection reset by peer
[error] error: Operation timed out
  1. What version of Swoole are you using (show your php --ri swoole)?
swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 5.1.2
Built => Jun  4 2024 09:09:32
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 3.3.0 9 Apr 2024
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
c-ares => 1.28.1
zlib => 1.3.1
brotli => E16781312/D16781312
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
async_redis => 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) ?
8be9af41998a:/app$ uname -a
Linux 8be9af41998a 5.15.0-116-generic #126-Ubuntu SMP Mon Jul 1 10:14:24 UTC 2024 x86_64 Linux
8be9af41998a:/app$ php -v
PHP 8.3.7 (cli) (built: May 22 2024 23:46:10) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.7, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.7, Copyright (c), by Zend Technologies
8be9af41998a:/app$ gcc -v
bash: gcc: command not found
@NathanFreeman
Copy link
Member

Fixed by #5413

@allsilaevex
Copy link
Author

@NathanFreeman yes, you are right
I tested in nightly image and the problem does not reproduce
thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants