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

v4.4.0使用Swoole\Event::add监听inotify异常 #2673

Closed
wangritian opened this issue Jul 10, 2019 · 9 comments
Closed

v4.4.0使用Swoole\Event::add监听inotify异常 #2673

wangritian opened this issue Jul 10, 2019 · 9 comments

Comments

@wangritian
Copy link

v4.4.0使用Swoole\Event::add监听inotify,文件变动时服务器segment fault,v4.3.5正常

@matyhtf
Copy link
Member

matyhtf commented Jul 10, 2019

请在程序末尾添加Event::wait(),另外,请贴出相关代码。

@wangritian
Copy link
Author

wangritian commented Jul 10, 2019

请在程序末尾添加Event::wait(),另外,请贴出相关代码。

use Swoole\Event as swEvent; ... $this->inotify = inotify_init(); ... swEvent::add($this->inotify, function ($inotify) { ... }

查了一下文档,PHP7.3版本是否不需要加wait了?
v4.3.5版本该代码正常运行,4.4.0更新后,一旦监听的文件变动产生事件,服务器就会崩溃
尝试过在回调函数的第一行打印日志,没有成功

@matyhtf
Copy link
Member

matyhtf commented Jul 10, 2019

4.4版本需要在末尾添加Event::wait()
请使用USE_ZEND_ALLOC=0 valgrind php your_file.php跟踪程序执行,贴出屏幕输出的错误信息

@matyhtf
Copy link
Member

matyhtf commented Jul 10, 2019

<?php
$fd = inotify_init();
$watch_descriptor = inotify_add_watch($fd, __FILE__, IN_ATTRIB);

swoole_event_add($fd, function($fd) {
    $info = inotify_read($fd);
    $queue_len = inotify_queue_len($fd);
    var_dump($info, $queue_len);
}, null, SWOOLE_EVENT_READ);

写了一个最简单的程序,无法重现你的问题。

@wangritian
Copy link
Author

wangritian commented Jul 10, 2019

4.4版本需要在末尾添加Event::wait()
请使用USE_ZEND_ALLOC=0 valgrind php your_file.php跟踪程序执行,贴出屏幕输出的错误信息

我在Swoole\Http\Server->start()之前,添加了Event::wait(),仍然报错,最后一块信息如下:

==19434== Conditional jump or move depends on uninitialised value(s)
==19434== at 0x4211959: ???
==19434== by 0x149D2AE7: ???
==19434== by 0x149D2AE7: ???
==19434== by 0x149D2AEC: ???
==19434== by 0x9D9531F: ???
==19434== by 0x149D2AE7: ???
==19434==
==19434== Conditional jump or move depends on uninitialised value(s)
==19434== at 0x4211986: ???
==19434== by 0x149D3437: ???
==19434== by 0x149D3437: ???
==19434== by 0x149D3442: ???
==19434== by 0x9D9531F: ???
==19434== by 0x149D3437: ???
==19434==
==19434== Conditional jump or move depends on uninitialised value(s)
==19434== at 0x4211986: ???
==19434== by 0x1471E667: ???
==19434== by 0x1471E667: ???
==19434== by 0x1471E673: ???
==19434== by 0x9D9531F: ???
==19434== by 0x1471E667: ???
==19434==
==19434== Conditional jump or move depends on uninitialised value(s)
==19434== at 0x3C8BA2: zend_string_equal_val (in /usr/bin/php7.3)
==19434== by 0x40DBF7: ??? (in /usr/bin/php7.3)
==19434== by 0x4289F6: execute_ex (in /usr/bin/php7.3)
==19434== by 0xA2CC723: swoole::PHPCoroutine::main_func(void*) (swoole_coroutine.cc:658)
==19434== by 0xA27FB2A: swoole::Context::context_func(void*) (context.cc:130)
==19434== by 0xA34B160: make_fcontext (make_x86_64_sysv_elf_gas.S:64)
==19434==
==19431== Jump to the invalid address stated on the next line
==19431== at 0x0: ???
==19431== by 0xA2A397F: swReactorEpoll_wait (epoll.c:257)
==19431== by 0xA2B240D: swReactorThread_start (reactor_thread.cc:993)
==19431== by 0xA2AAFEA: swServer_start (master.cc:688)
==19431== by 0xA3255BE: zim_swoole_server_start(_zend_execute_data*, _zval_struct*) (swoole_server.cc:2769)
==19431== by 0x42E6F5: execute_ex (in /usr/bin/php7.3)
==19431== by 0x42E989: zend_execute (in /usr/bin/php7.3)
==19431== by 0x39F3D2: zend_execute_scripts (in /usr/bin/php7.3)
==19431== by 0x33DAB7: php_execute_script (in /usr/bin/php7.3)
==19431== by 0x430E0E: ??? (in /usr/bin/php7.3)
==19431== by 0x1F6B31: ??? (in /usr/bin/php7.3)
==19431== by 0x6BAE2E0: (below main) (libc-start.c:291)
==19431== Address 0x0 is not stack'd, malloc'd or (recently) free'd
==19431==
==19431==
==19431== Process terminating with default action of signal 11 (SIGSEGV)
==19431== Bad permissions for mapped region at address 0x0
==19431== at 0x0: ???
==19431== by 0xA2A397F: swReactorEpoll_wait (epoll.c:257)
==19431== by 0xA2B240D: swReactorThread_start (reactor_thread.cc:993)
==19431== by 0xA2AAFEA: swServer_start (master.cc:688)
==19431== by 0xA3255BE: zim_swoole_server_start(_zend_execute_data*, _zval_struct*) (swoole_server.cc:2769)
==19431== by 0x42E6F5: execute_ex (in /usr/bin/php7.3)
==19431== by 0x42E989: zend_execute (in /usr/bin/php7.3)
==19431== by 0x39F3D2: zend_execute_scripts (in /usr/bin/php7.3)
==19431== by 0x33DAB7: php_execute_script (in /usr/bin/php7.3)
==19431== by 0x430E0E: ??? (in /usr/bin/php7.3)
==19431== by 0x1F6B31: ??? (in /usr/bin/php7.3)
==19431== by 0x6BAE2E0: (below main) (libc-start.c:291)
==19431==
==19431== HEAP SUMMARY:
==19431== in use at exit: 5,916,118 bytes in 25,780 blocks
==19431== total heap usage: 43,468 allocs, 17,688 frees, 11,869,813 bytes allocated
==19431==
==19431== LEAK SUMMARY:
==19431== definitely lost: 936 bytes in 39 blocks
==19431== indirectly lost: 400 bytes in 12 blocks
==19431== possibly lost: 1,924,806 bytes in 14,751 blocks
==19431== still reachable: 3,989,976 bytes in 10,978 blocks
==19431== suppressed: 0 bytes in 0 blocks
==19431== Rerun with --leak-check=full to see details of leaked memory
==19431==
==19431== For counts of detected and suppressed errors, rerun with: -v
==19431== Use --track-origins=yes to see where uninitialised values come from
==19431== ERROR SUMMARY: 7840 errors from 183 contexts (suppressed: 0 from 0)
Killed
root@debian:~/service# [2019-07-10 14:50:07 *19434.0] WARNING swWorker_reactor_is_empty (ERRNO 9012): worker exit timeout, forced to terminate
==19434==
==19434== HEAP SUMMARY:
==19434== in use at exit: 6,141,337 bytes in 24,461 blocks
==19434== total heap usage: 56,937 allocs, 32,476 frees, 47,282,318 bytes allocated
==19434==
==19434== LEAK SUMMARY:
==19434== definitely lost: 2,032 bytes in 78 blocks
==19434== indirectly lost: 552,184 bytes in 28 blocks
==19434== possibly lost: 2,024,918 bytes in 15,768 blocks
==19434== still reachable: 3,562,203 bytes in 8,587 blocks
==19434== suppressed: 0 bytes in 0 blocks
==19434== Rerun with --leak-check=full to see details of leaked memory
==19434==
==19434== For counts of detected and suppressed errors, rerun with: -v
==19434== Use --track-origins=yes to see where uninitialised values come from
==19434== ERROR SUMMARY: 13950 errors from 288 contexts (suppressed: 0 from 0)
==19432==
==19432== HEAP SUMMARY:
==19432== in use at exit: 4,995,190 bytes in 21,448 blocks
==19432== total heap usage: 42,982 allocs, 21,534 frees, 10,695,985 bytes allocated
==19432==
==19432== LEAK SUMMARY:
==19432== definitely lost: 936 bytes in 39 blocks
==19432== indirectly lost: 400 bytes in 12 blocks
==19432== possibly lost: 1,841,574 bytes in 14,747 blocks
==19432== still reachable: 3,152,280 bytes in 6,650 blocks
==19432== suppressed: 0 bytes in 0 blocks
==19432== Rerun with --leak-check=full to see details of leaked memory
==19432==
==19432== For counts of detected and suppressed errors, rerun with: -v
==19432== Use --track-origins=yes to see where uninitialised values come from
==19432== ERROR SUMMARY: 7742 errors from 180 contexts (suppressed: 0 from 0)
^C

我的安装脚本:
#!/usr/bin/env bash
apt-get update -y
apt-get install -y software-properties-common apt-transport-https lsb-release ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://mirror.xtom.com.hk/sury/php/apt.gpg
sh -c 'echo "deb https://mirror.xtom.com.hk/sury/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
apt-get update -y
apt-get install -y --allow-unauthenticated git zip php7.3 php7.3-dev php7.3-xml php7.3-mbstring uuid-dev
systemctl stop apache2
git clone -b v4.4.0 https://gitee.com/swoole/swoole.git
cd swoole
phpize
./configure --enable-mysqlnd --enable-openssl
make
make install
echo -e "\nextension = swoole.so" >> /etc/php/7.3/cli/php.ini
cd ../
rm -rf swoole
pecl install inotify
echo -e "\nextension = inotify.so" >> /etc/php/7.3/cli/php.ini
curl -sS https://getcomposer.org/installer -o composer.php
php composer.php --install-dir=/usr/local/bin --filename=composer
composer install
rm composer.php

@wangritian
Copy link
Author

<?php
$fd = inotify_init();
$watch_descriptor = inotify_add_watch($fd, __FILE__, IN_ATTRIB);

swoole_event_add($fd, function($fd) {
    $info = inotify_read($fd);
    $queue_len = inotify_queue_len($fd);
    var_dump($info, $queue_len);
}, null, SWOOLE_EVENT_READ);

写了一个最简单的程序,无法重现你的问题。

我inotify监听的事件是:IN_MODIFY | IN_CREATE | IN_DELETE | IN_MOVE | IN_ISDIR

@matyhtf
Copy link
Member

matyhtf commented Jul 10, 2019

无法重现你的问题,请提供一个可以重现的 demo 程序,提供复现的步骤。

@wangritian
Copy link
Author

wangritian commented Jul 10, 2019

无法重现你的问题,请提供一个可以重现的 demo 程序,提供复现的步骤。

简化代码:

$server = new Swoole\Http\Server('0.0.0.0', 8080);
$server->set([
    'dispatch_mode'      => 1,
    'daemonize'          => false,
    'package_max_length' => 1024 * 1024 * 10,
    'open_cpu_affinity'  => true,
    'open_tcp_nodelay'   => true,
    'enable_reuse_port'  => true,
    'reload_async'       => true,
    'tcp_fastopen'       => true,
    'enable_coroutine'   => true,
    'max_coroutine'      => 10000,
    'max_wait_time'      => 60,
]);
$server->on('start', function () {
    $fd = inotify_init();
    inotify_add_watch($fd, '/root/swoole/a.txt', IN_MODIFY | IN_CREATE | IN_DELETE | IN_MOVE | IN_ISDIR);
    Swoole\Event::add($fd, function ($inotify) {
        $event = inotify_read($inotify);
        print_r($event);
    });
});
$server->on('request', function ($req, $res) {
    $res->end('');
});
Swoole\Event::wait();
$server->start();

内核版本:
Linux debian 4.9.0-9-amd64 #1 SMP Debian 4.9.168-1 (2019-04-12) x86_64 GNU/Linux

swoole版本:
Swoole => enabled
Author => Swoole Team team@swoole.com
Version => 4.4.0
Built => Jul 10 2019 20:00:18
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.1.1b 26 Feb 2019
http2 => enabled
pcre => enabled
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

安装脚本:
#!/usr/bin/env bash
apt-get update -y
apt-get install -y software-properties-common apt-transport-https lsb-release ca-certificates
wget -O /etc/apt/trusted.gpg.d/php.gpg https://mirror.xtom.com.hk/sury/php/apt.gpg
sh -c 'echo "deb https://mirror.xtom.com.hk/sury/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
apt-get update -y
apt-get install -y --allow-unauthenticated git zip php7.3 php7.3-dev php7.3-xml php7.3-mbstring
systemctl stop apache2
git clone -b v4.4.0 https://gitee.com/swoole/swoole.git
cd swoole
phpize
./configure --enable-mysqlnd --enable-openssl
make
make install
echo -e "\nextension = swoole.so" >> /etc/php/7.3/cli/php.ini
cd ../
rm -rf swoole
pecl install inotify
echo -e "\nextension = inotify.so" >> /etc/php/7.3/cli/php.ini
curl -sS https://getcomposer.org/installer -o composer.php
php composer.php --install-dir=/usr/local/bin --filename=composer
composer install
rm composer.php

@wangritian
Copy link
Author

wangritian commented Jul 11, 2019

无法重现你的问题,请提供一个可以重现的 demo 程序,提供复现的步骤。

您好,重新编译v4.4.0后,仍然崩溃,是否需要提供更多信息?

切换到master分支已经可以了,刚刚是指定的tag,感谢

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