swoole-src icon indicating copy to clipboard operation
swoole-src copied to clipboard

Timer::add() (ERRNO 505): msec value[0] is invalid

Open z6824980 opened this issue 3 years ago • 7 comments

Please answer these questions before submitting your issue.

  1. What did you do? If possible, provide a simple script for reproducing the error. 想了解下什么情况下会导致这个警告,业务代码里面没有主动使用timer之类的函数。 出现这个警告需要关注么,偶发。

  2. What did you expect to see? 有何办法解决这个警告? 对业务上会有什么影响?

  3. What did you see instead? WARNING Timer::add() (ERRNO 505): msec value[0] is invalid

  4. What version of Swoole are you using (show your php --ri swoole)? Swoole => enabled Author => Swoole Team [email protected] Version => 4.8.8 Built => Jul 7 2022 11:30:56 coroutine => enabled with boost asm context epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled pcre => enabled zlib => 1.2.7 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) ? Linux 7b828a91fe35 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux php7.2

z6824980 avatar Aug 08 '22 10:08 z6824980

我待会看看是什么原因

NathanFreeman avatar Aug 08 '22 12:08 NathanFreeman

有使用过Channel吗

NathanFreeman avatar Aug 08 '22 13:08 NathanFreeman

目前这个项目没有使用过channel

z6824980 avatar Aug 09 '22 09:08 z6824980

image 这是加的配置

z6824980 avatar Aug 09 '22 09:08 z6824980

image 结束worker处理的逻辑

z6824980 avatar Aug 09 '22 09:08 z6824980

image swoole.log日志

z6824980 avatar Aug 09 '22 09:08 z6824980

我大概会在这周提一个这个pr

NathanFreeman avatar Aug 09 '22 16:08 NathanFreeman

image 上面修改的内容,是下个小版本上吗, 我的swoole版本也需要更新吧, 现在是这个版本。 image

z6824980 avatar Aug 15 '22 03:08 z6824980

还想知道的是, 这个WARNING Timer::add() (ERRNO 505): msec value[0] is invalid 如果不修复会影响哪块呢? 目前看服务各指标,没看到明显的异常点

z6824980 avatar Aug 15 '22 03:08 z6824980

我没看过你的代码,有可能是你们使用了有超时参数的函数,然后超时时间是一个小于1毫秒的的值,所以有这个警告。

NathanFreeman avatar Aug 15 '22 04:08 NathanFreeman

这个有可能,可能有一些i/o函数,curl curl_multi_select fsockopen socket stream之类的,
还有usleep(50) 这个函数设置的。 image

z6824980 avatar Aug 15 '22 04:08 z6824980

while (($dtUsec = $obj->_restTime($obj->_readWriteTimeoutUs, $obj->stime)) > 0 && stream_select($r, $w, $e, 0, $dtUsec) !== 0)

项目中有一段这个函数, 第四位秒数传0,第五位传的微秒数, swoole hook后底层应该不认为add第一个参数是无效的吧。

z6824980 avatar Aug 15 '22 08:08 z6824980

还有这个函数:第二位秒数传0,第三位传的微秒数 if (!stream_set_timeout($sock, 0, $timeoutUsec)) { return false; }

z6824980 avatar Aug 15 '22 08:08 z6824980

还有这个函数:第二位秒数传0,第三位传的微秒数 if (!stream_set_timeout($sock, 0, $timeoutUsec)) { return false; }

有可能是这个引起的

NathanFreeman avatar Aug 15 '22 09:08 NathanFreeman

while (($dtUsec = $obj->_restTime($obj->_readWriteTimeoutUs, $obj->stime)) > 0 && stream_select($r, $w, $e, 0, $dtUsec) !== 0)

项目中有一段这个函数, 第四位秒数传0,第五位传的微秒数, swoole hook后底层应该不认为add第一个参数是无效的吧。

这个原本就有小于0.001就重置为0.001的判断

NathanFreeman avatar Aug 15 '22 09:08 NathanFreeman

我看源码测试用例里面有这种案例,应该不是 stream_set_timeout($sock, 0, $timeoutUsec) 这个导致的,我再查一查。 image

z6824980 avatar Aug 15 '22 10:08 z6824980

应该是这个函数导致的:stream_set_timeout($sock, 0, $timeoutUsec),我把0改成1压测,1个小时左右都没有再报那个警告 Timer::add() (ERRNO 505): msec value[0] is invalid image

按官方的解释,这个函数是 “以秒和微秒的总和表示”,单独设置微秒应该也是可以的。 image

z6824980 avatar Aug 15 '22 11:08 z6824980

这块的场景应该是 设置的超时时间小于1秒,比如800ms, 这里应该设置成 stream_set_timeout($sock, 0, 800000), 就会报这个问题, 看看是不是要修复一下。

z6824980 avatar Aug 15 '22 11:08 z6824980

这块的场景应该是 设置的超时时间小于1秒,比如800ms, 这里应该设置成 stream_set_timeout($sock, 0, 800000), 就会报这个问题, 看看是不是要修复一下。

800毫秒不会有问题,转化成秒就是0.8秒,大于0.001秒

NathanFreeman avatar Aug 16 '22 01:08 NathanFreeman