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

'max_request_execution_time' not working when 'enable_coroutine' => false #136

Closed sebastianwos closed 2 years ago

sebastianwos commented 2 years ago

Is it possible to make 'max_request_execution_time' work for all HttpServer config, even when coroutine are disabled ?

doubaokun commented 2 years ago

max_request_execution_time is supported in both coroutine and non-coroutine mode. But it may be delayed or blocked by syscall like sleep in non-coroutine mode when you are testing.

smortexa commented 2 years ago

@doubaokun The max_request_execution_time doesn't work in Laravel Octane (non-coroutine mode). It can be reproduced without sleep:

Route::get('/foo', function (Request $request) {
    for (;;){
    }
    return 'bar';
});

// config/octane.php

'swoole' => [
        'options' => [
            'max_request_execution_time' => 5,
        ]
    ]
doubaokun commented 2 years ago

In real world applications, it should work. for (;;){ } is busy looping at CPU and there’s no chance for other code to be executed like termination.

smortexa commented 2 years ago

@doubaokun I tried this, but It still doesn't work:

Route::get('/foo', function (Request $request) {
    // 5s I/O operation
    \Illuminate\Support\Facades\Http::get('https://reqres.in/api/users?delay=5');
    return 'bar';
});

// config/octane.php

'swoole' => [
        'options' => [
            'max_request_execution_time' => 3,
        ]
    ]
doubaokun commented 2 years ago

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

smortexa commented 2 years ago
openswoole

Open Swoole => enabled
Author => Open Swoole Group <hello@openswoole.com>
Version => 4.10.0
Built => Mar  2 2022 19:28:03
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.1.1f  31 Mar 2020
dtls => enabled
http2 => enabled
curl-native => enabled
zlib => 1.2.11
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_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
doubaokun commented 2 years ago

Will have another check later.

smortexa commented 2 years ago

@doubaokun Any news on this?

doubaokun commented 2 years ago

It is the expected behavior, if you don't enable coroutines in your application, the application may be blocked at syscalls such as CURL, sockets etc.