Open
Description
Tps:
这个问题目前只存在于pecl安装的swoole(包括手动编译),在swoole-cli中没有此问题,且锁类型只有 SWOOLE_RWLOCK 才会存在这个问题.
目前测试过的php8.0-8.2 swoole4.8-5.0都成功复现。
为了确定非扩展兼容问题,其它扩展禁用情况下依然复现。
为了确保描述可靠,这里增加一些描述
注意!这是一个bug!并非功能性增强,pecl下安装的swoole存在跨进程解锁返回true,但实际上解锁失败卡住的问题,这个问题只有php-cli模式下的读写锁才会存在,测试swoole-cli与其它锁类型都不会触发这个bug!
- What did you do? If possible, provide a simple script for reproducing the error.
install
./configure --prefix=/test/php --disable-all --enable-pcntl --enable-swoole
make
make install
$lock = new \Swoole\Lock(SWOOLE_RWLOCK);
for ($i = 0; $i < 5; $i++) {
$pid = pcntl_fork();
if ($pid == -1) {
var_dump("error");
} elseif ($pid == 0) {
if ($i === 3) {
sleep(3);
var_dump("$i try unlock", $lock->unlock());
}
var_dump("$i try lock");
if ($lock->lock()) {
sleep(1); # 避免打印堆积无法正常显示
var_dump("$i lock success");
}
if ($i === 0) {
var_dump("$i not unlock, out");
exit;
}
var_dump("$i lock close", $lock->unlock());
exit;
}
}
while (pcntl_wait($status) != -1) {
}
var_dump("End");
- What did you expect to see?
success unlock in swoole-cli
[root@centos8 test]# swoole test.php
string(10) "0 try lock"
string(10) "1 try lock"
string(10) "2 try lock"
string(10) "4 try lock"
string(14) "0 lock success"
string(17) "0 not unlock, out"
string(12) "3 try unlock"
bool(true)
string(10) "3 try lock"
string(14) "1 lock success"
string(12) "1 lock close"
bool(true)
string(14) "2 lock success"
string(12) "2 lock close"
bool(true)
string(14) "3 lock success"
string(12) "3 lock close"
bool(true)
string(14) "4 lock success"
string(12) "4 lock close"
bool(true)
string(3) "End"
- What did you see instead?
display success unlock but not unlock in php-cli
[root@centos8 test]# php test.php
string(10) "0 try lock"
string(10) "1 try lock"
string(10) "2 try lock"
string(10) "4 try lock"
string(14) "0 lock success"
string(17) "0 not unlock, out"
string(12) "3 try unlock"
bool(true)
string(10) "3 try lock"
^C # loading..... so ctrl c
[root@centos8 test]#
- What version of Swoole are you using (show your
php --ri swoole
)?
swoole
Swoole => enabled
Author => Swoole Team <[email protected]>
Version => 5.0.2
Built => Apr 9 2023 23:45:05
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
http2 => enabled
json => enabled
pcre => enabled
zlib => 1.2.11
mutex_timedlock => enabled
pthread_barrier => enabled
futex => 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
- What is your machine environment used (show your
uname -a
&php -v
&gcc -v
) ?
centos8