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

lock bug occurs after pecl installs swoole in php8.0-8.2 #5024

Open
AliceSync opened this issue Apr 9, 2023 · 5 comments
Open

lock bug occurs after pecl installs swoole in php8.0-8.2 #5024

AliceSync opened this issue Apr 9, 2023 · 5 comments

Comments

@AliceSync
Copy link

AliceSync commented Apr 9, 2023

Tps:

这个问题目前只存在于pecl安装的swoole(包括手动编译),在swoole-cli中没有此问题,且锁类型只有 SWOOLE_RWLOCK 才会存在这个问题.
目前测试过的php8.0-8.2 swoole4.8-5.0都成功复现。
为了确定非扩展兼容问题,其它扩展禁用情况下依然复现。

为了确保描述可靠,这里增加一些描述
注意!这是一个bug!并非功能性增强,pecl下安装的swoole存在跨进程解锁返回true,但实际上解锁失败卡住的问题,这个问题只有php-cli模式下的读写锁才会存在,测试swoole-cli与其它锁类型都不会触发这个bug!

  1. 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");
  1. 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"
  1. 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]# 
  1. What version of Swoole are you using (show your php --ri swoole)?
swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
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
  1. What is your machine environment used (show your uname -a & php -v & gcc -v) ?

centos8

@NathanFreeman
Copy link
Member

NathanFreeman commented Apr 10, 2023

因为Swoole lock设计上是用来实现进程同步的,底层采用的是共享内存,所以只要一个子进程没解锁,剩下的子进程都得阻塞。

@AliceSync
Copy link
Author

因为Swoole lock设计上是用来实现进程同步的,底层采用的是共享内存,所以只要一个子进程没解锁,剩下的子进程都得阻塞。

你应该查看一下代码再说,我是说读写锁在跨进程解锁存在bug,因为swoole-cli的单文件是不存在这个问题的,这个bug只存在于读写锁且属于普通php模式下pecl库安装的swoole才会触发

@NathanFreeman
Copy link
Member

好的,我再测试看看😁。

@AliceSync
Copy link
Author

好的,我再测试看看😁。

我顺便补充了一下在我本机测试的输出结果,就那串代码,你用swoole-cli和php-cli分别运行一次就知道了,还有很奇怪这个bug只有读写锁会,互斥之类的锁都不会,我也是在自动化覆盖测试卡住才发现的

@NathanFreeman
Copy link
Member

好的,谢谢

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