hyperf / hyperf

🚀 A coroutine framework that focuses on hyperspeed and flexibility. Building microservice or middleware with ease.
https://www.hyperf.io
MIT License
6.26k stars 1.22k forks source link

[BUG] 升级Swoole4.6后,链路追踪Jaeger报错 #3124

Closed songguoxiong closed 3 years ago

songguoxiong commented 3 years ago

Execute the command and paste the result below.

Command: uname -a && php -v && composer info | grep hyperf && php --ri swoole

Darwin  20.2.0 Darwin Kernel Version 20.2.0: Wed Dec  2 20:39:59 PST 2020; root:xnu-7195.60.75~1/RELEASE_X86_64 x86_64
PHP 7.4.14 (cli) (built: Jan  8 2021 13:20:04) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Sdebug v2.9.3-dev, Copyright (c) 2002-2020, by Derick Rethans
    with Zend OPcache v7.4.14, Copyright (c), by Zend Technologies
hyperf/amqp                          v2.1.0             A amqplib for hyperf.
hyperf/cache                         v2.1.0             A cache component for hyperf.
hyperf/command                       v2.1.0             Command for hyperf
hyperf/config                        v2.1.0             An independent component that provides configuration container.
hyperf/constants                     v2.1.0             A constants component for hyperf.
hyperf/contract                      v2.1.0             The contracts of Hyperf.
hyperf/crontab                       v2.1.0             A crontab component for Hyperf.
hyperf/database                      v2.1.2             A flexible database library.
hyperf/db-connection                 v2.1.0             A hyperf db connection handler for hyperf/database.
hyperf/devtool                       v2.1.2             A Devtool for Hyperf.
hyperf/di                            v2.1.2             A DI for Hyperf.
hyperf/dispatcher                    v2.1.0             A HTTP Server for Hyperf.
hyperf/elasticsearch                 v2.1.0             Elasticsearch client for hyperf
hyperf/engine                        v1.0.2
hyperf/event                         v2.1.0             an event manager that implements PSR-14.
hyperf/exception-handler             v2.1.1             Exception handler for hyperf
hyperf/filesystem                    v2.1.2             flysystem integration for hyperf
hyperf/framework                     v2.1.1             A coroutine framework that focuses on hyperspeed and flexible, specifically use for build microservices and middlewares.
hyperf/guzzle                        v2.1.1             Swoole coroutine handler for guzzle
hyperf/http-message                  v2.1.1             microservice framework base on swoole
hyperf/http-server                   v2.1.0             A HTTP Server for Hyperf.
hyperf/logger                        v2.1.0             A logger component for hyperf.
hyperf/memory                        v2.1.0             An independent component that use to operate and manage memory.
hyperf/model-listener                v2.1.0             A model listener for Hyperf.
hyperf/pool                          v2.1.0             An independent universal connection pool component.
hyperf/process                       v2.1.0             A process component for hyperf.
hyperf/redis                         v2.1.0             A redis component for hyperf.
hyperf/retry                         v2.1.0             A retry component for hyperf.
hyperf/scout                         v2.1.2             Hyperf Scout provides a driver based solution to searching your Eloquent models. Inspired By Laravel Scout.
hyperf/server                        v2.1.0             A base server library for Hyperf.
hyperf/snowflake                     v2.1.0             A snowflake library
hyperf/testing                       v2.1.0             Testing for hyperf
hyperf/tracer                        v2.1.0             A open tracing system implemented for Hyperf or other coroutine framework
hyperf/translation                   v2.1.0             An independent translation component, forked by illuminate/translation.
hyperf/utils                         v2.1.2             A tools package that could help developer solved the problem quickly.
hyperf/validation                    v2.1.1             hyperf validation

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.6.1
Built => Jan 13 2021 17:29:50
coroutine => enabled with boost asm context
kqueue => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.1.1i  8 Dec 2020
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
zlib => 1.2.11
brotli => E16777225/D16777225
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 => Off => Off
swoole.unixsock_buffer_size => 262144 => 262144

Description:

Fatal error: Uncaught TypeError: Argument 1 passed to swoole_socket_write() must be an instance of Swoole\Coroutine\Socket, resource given in @swoole-src/library/ext/sockets.php on line 32

TypeError: Argument 1 passed to swoole_socket_write() must be an instance of Swoole\Coroutine\Socket, resource given in @swoole-src/library/ext/sockets.php on line 32

Call Stack:
  246.5089  283757768   1. Hyperf\Tracer\Middleware\TraceMiddleware->Hyperf\Tracer\Middleware\{closure:xxx/vendor/hyperf/tracer/src/Middleware/TraceMiddleware.php:47-49}() xxx/vendor/hyperf/tracer/src/Middleware/TraceMiddleware.php:0
  246.5089  283757768   2. Jaeger\Tracer->flush() xxx/vendor/hyperf/tracer/src/Middleware/TraceMiddleware.php:48
  246.5089  283757768   3. Jaeger\Reporter\RemoteReporter->close() xxx/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Tracer.php:278
  246.5089  283757768   4. Jaeger\Sender\UdpSender->flush() xxx/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Reporter/RemoteReporter.php:45
  246.5103  283783488   5. Jaeger\Sender\UdpSender->send() xxx/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Sender/UdpSender.php:93
  246.5193  283798824   6. Jaeger\Thrift\Agent\AgentClient->emitZipkinBatch() xxx/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Sender/UdpSender.php:116
  246.5193  283798824   7. Jaeger\Thrift\Agent\AgentClient->send_emitZipkinBatch() xxx/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Thrift/Agent/AgentClient.php:32
  246.5310  283809896   8. Thrift\Transport\TBufferedTransport->flush() xxx/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/Thrift/Agent/AgentClient.php:49
  246.5310  283809896   9. Jaeger\ThriftUdpTransport->write() xxx/vendor/packaged/thrift/src/Thrift/Transport/TBufferedTransport.php:176
  246.5310  283809896  10. socket_write() xxx/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/ThriftUdpTransport.php:99
  246.5310  283809896  11. swoole_socket_write() xxx/vendor/jonahgeorge/jaeger-client-php/src/Jaeger/ThriftUdpTransport.php:99

hyperf.php里是

!defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL);

docker使用的base镜像是hyperf/hyperf:7.4-alpine-v3.11-swoole

Steps To Reproduce:

limingxinleo commented 3 years ago

@sy-records

sy-records commented 3 years ago

这个只能自己改代码或者关闭hook sockets。创建的时候不在协程里没有hook,在协程里的时候被hook,类型不对了

Reasno commented 3 years ago

暂时先关闭hook,后面会解决。

!defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL ^ SWOOLE_HOOK_SOCKETS);
songguoxiong commented 3 years ago

原来的问题没有了,有了新的报错。 好像是swoole返回的类型和原生的类型不一致,原生是int | bool,swoole是int

[WARNING] TypeError: Return value of swoole_socket_write() must be of the type int, bool returned(0) in @swoole-src/library/ext/sockets.php:37
Stack trace:
#0 [internal function]: swoole_socket_write(Object(Swoole\Coroutine\Socket), '\x82\x81\x00\x0FemitZipkinB...')
#1 xxx/vendor/hyperf/tracer/class_map/ThriftUdpTransport.php(163): socket_write(Object(Swoole\Coroutine\Socket), '\x82\x81\x00\x0FemitZipkinB...')
#2 xxx/vendor/hyperf/tracer/class_map/ThriftUdpTransport.php(144): Jaeger\ThriftUdpTransport->doWrite('\x82\x81\x00\x0FemitZipkinB...')
#3 [internal function]: Jaeger\ThriftUdpTransport->Jaeger\{closure}()
#4 xxx/vendor/hyperf/tracer/class_map/ThriftUdpTransport.php(180): Closure->call(Object(Jaeger\ThriftUdpTransport))
#5 xxx/vendor/hyperf/utils/src/Functions.php(271): Jaeger\ThriftUdpTransport->Jaeger\{closure}()
#6 xxx/vendor/hyperf/utils/src/Coroutine.php(62): call(Object(Closure))
#7 {main}

https://github.com/swoole/library/blob/73e892e45b3794591cd5190f143b80d664755085/src/ext/sockets.php#L32

songguoxiong commented 3 years ago

@sy-records

ysk229 commented 3 years ago

原来的问题没有了,有了新的报错。 好像是swoole返回的类型和原生的类型不一致,原生是int | bool,swoole是int

[WARNING] TypeError: Return value of swoole_socket_write() must be of the type int, bool returned(0) in @swoole-src/library/ext/sockets.php:37
Stack trace:
#0 [internal function]: swoole_socket_write(Object(Swoole\Coroutine\Socket), '\x82\x81\x00\x0FemitZipkinB...')
#1 xxx/vendor/hyperf/tracer/class_map/ThriftUdpTransport.php(163): socket_write(Object(Swoole\Coroutine\Socket), '\x82\x81\x00\x0FemitZipkinB...')
#2 xxx/vendor/hyperf/tracer/class_map/ThriftUdpTransport.php(144): Jaeger\ThriftUdpTransport->doWrite('\x82\x81\x00\x0FemitZipkinB...')
#3 [internal function]: Jaeger\ThriftUdpTransport->Jaeger\{closure}()
#4 xxx/vendor/hyperf/tracer/class_map/ThriftUdpTransport.php(180): Closure->call(Object(Jaeger\ThriftUdpTransport))
#5 xxx/vendor/hyperf/utils/src/Functions.php(271): Jaeger\ThriftUdpTransport->Jaeger\{closure}()
#6 xxx/vendor/hyperf/utils/src/Coroutine.php(62): call(Object(Closure))
#7 {main}

https://github.com/swoole/library/blob/73e892e45b3794591cd5190f143b80d664755085/src/ext/sockets.php#L32

大佬,解决了吗?我遇到这样的情况??? @songguoxiong

songguoxiong commented 3 years ago

原来的问题了,随之而来的新的报错 好像是羊毛返回的类型和自己的类型没有特征,本身就是int | bool,swoole 是int

[WARNING] TypeError: Return value of swoole_socket_write() must be of the type int, bool returned(0) in @swoole-src/library/ext/sockets.php:37
Stack trace:
#0 [internal function]: swoole_socket_write(Object(Swoole\Coroutine\Socket), '\x82\x81\x00\x0FemitZipkinB...')
#1 xxx/vendor/hyperf/tracer/class_map/ThriftUdpTransport.php(163): socket_write(Object(Swoole\Coroutine\Socket), '\x82\x81\x00\x0FemitZipkinB...')
#2 xxx/vendor/hyperf/tracer/class_map/ThriftUdpTransport.php(144): Jaeger\ThriftUdpTransport->doWrite('\x82\x81\x00\x0FemitZipkinB...')
#3 [internal function]: Jaeger\ThriftUdpTransport->Jaeger\{closure}()
#4 xxx/vendor/hyperf/tracer/class_map/ThriftUdpTransport.php(180): Closure->call(Object(Jaeger\ThriftUdpTransport))
#5 xxx/vendor/hyperf/utils/src/Functions.php(271): Jaeger\ThriftUdpTransport->Jaeger\{closure}()
#6 xxx/vendor/hyperf/utils/src/Coroutine.php(62): call(Object(Closure))
#7 {main}

https://github.com/swoole/library/blob/73e892e45b3794591cd5190f143b80d664755085/src/ext/sockets.php#L32

大佬,解决了吗?我遇到这样的情况??? @songguoxiong

没有,我们后面swoole回退到了4.5