首页
下载
文档
社区
视频
捐赠
源代码
赞助商
AOT 编译器
AI 助理
商业产品
PHP AOT 原生编译器
Swoole-Compiler 代码加密器
CRMEB 新零售社交电商系统
登录
注册
全部
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
发表新帖
协程 http 客户端响应,解析错误,body 包含了 header
### 问题描述 使用了 hyperf/guzzle 协程 handler 替换了 guzzle 的默认 handler(由 swoole 官方的 http 协程客户端实现),偶发一些情况 body 包含了头部信息,例如(这是 body) `HTTP/1.1 200 OK Date: Tue, 28 Apr 2020 11:04:14 GMT Content-Type: application/json; charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive Cache-Control: max-age=0 Access-Control-Allow-Origin: * 1d {"code":0,"msg":"","data":""} 0 ` 通过 debug 发现原始的 swoole http client 已经解析错误,也就是说与 hyperf 无关: `["statusCode"]=> int(100) ["headers"]=> NULL ["set_cookie_headers"]=> NULL ["cookies"]=> NULL ["body"]=> string(253) "HTTP/1.1 200 OK Date: Tue, 28 Apr 2020 11:04:14 GMT Content-Type: application/json; charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive Cache-Control: max-age=0 Access-Control-Allow-Origin: * 1d {"code":0,"msg":"","data":""} 0 " }` ### Swoole版本,PHP版本,以及操作系统版本信息 swoole 版本: swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.4.14 Built => Feb 11 2020 23:24:02 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled sockets => enabled openssl => OpenSSL 1.0.2k-fips 26 Jan 2017 http2 => enabled pcre => enabled zlib => 1.2.7 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 PHP 版本 PHP 7.3.11 (cli) (built: Nov 5 2019 17:45:45) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.11, Copyright (c) 1999-2018, by Zend Technologies 系统版本 [xm@crm-edm-vpc protected]$ cat /etc/os-release NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7" [xm@crm-edm-vpc protected]$ uname -a Linux crm-edm-vpc 3.10.0-1062.4.1.el7.x86_64 #1 SMP Fri Oct 18 17:15:30 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux ### 相关代码 恕不能提供代码,参数和服务器都是敏感信息。我能确认的是在非协程环境是可以正常请求的。并且触发 bug 和参数关系很大,因为我们处理几十万请求,偶尔出现十几个异常的情况,异常情况单独在新进程和协程执行能复现。 ### 你期待的结果是什么?实际看到的错误信息又是什么? 期待 header 内容不要被解析到 body,body 能正常就好。
发布于6年前 · 2 次浏览 · 来自
提问
Pear
### 问题描述 使用了 hyperf/guzzle 协程 handler 替换了 guzzle 的默认 handler(由 swoole 官方的 http 协程客户端实现),偶发一些情况 body 包含了头部信息,例如(这是 body) `HTTP/1.1 200 OK Date: Tue, 28 Apr 2020 11:04:14 GMT Content-Type: application/json; charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive Cache-Control: max-age=0 Access-Control-Allow-Origin: * 1d {"code":0,"msg":"","data":""} 0 ` 通过 debug 发现原始的 swoole http client 已经解析错误,也就是说与 hyperf 无关: `["statusCode"]=> int(100) ["headers"]=> NULL ["set_cookie_headers"]=> NULL ["cookies"]=> NULL ["body"]=> string(253) "HTTP/1.1 200 OK Date: Tue, 28 Apr 2020 11:04:14 GMT Content-Type: application/json; charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive Cache-Control: max-age=0 Access-Control-Allow-Origin: * 1d {"code":0,"msg":"","data":""} 0 " }` ### Swoole版本,PHP版本,以及操作系统版本信息 swoole 版本: swoole Swoole => enabled Author => Swoole Team <team@swoole.com> Version => 4.4.14 Built => Feb 11 2020 23:24:02 coroutine => enabled epoll => enabled eventfd => enabled signalfd => enabled cpu_affinity => enabled spinlock => enabled rwlock => enabled sockets => enabled openssl => OpenSSL 1.0.2k-fips 26 Jan 2017 http2 => enabled pcre => enabled zlib => 1.2.7 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 PHP 版本 PHP 7.3.11 (cli) (built: Nov 5 2019 17:45:45) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.11, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.11, Copyright (c) 1999-2018, by Zend Technologies 系统版本 [xm@crm-edm-vpc protected]$ cat /etc/os-release NAME="CentOS Linux" VERSION="7 (Core)" ID="centos" ID_LIKE="rhel fedora" VERSION_ID="7" PRETTY_NAME="CentOS Linux 7 (Core)" ANSI_COLOR="0;31" CPE_NAME="cpe:/o:centos:centos:7" HOME_URL="https://www.centos.org/" BUG_REPORT_URL="https://bugs.centos.org/" CENTOS_MANTISBT_PROJECT="CentOS-7" CENTOS_MANTISBT_PROJECT_VERSION="7" REDHAT_SUPPORT_PRODUCT="centos" REDHAT_SUPPORT_PRODUCT_VERSION="7" [xm@crm-edm-vpc protected]$ uname -a Linux crm-edm-vpc 3.10.0-1062.4.1.el7.x86_64 #1 SMP Fri Oct 18 17:15:30 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux ### 相关代码 恕不能提供代码,参数和服务器都是敏感信息。我能确认的是在非协程环境是可以正常请求的。并且触发 bug 和参数关系很大,因为我们处理几十万请求,偶尔出现十几个异常的情况,异常情况单独在新进程和协程执行能复现。 ### 你期待的结果是什么?实际看到的错误信息又是什么? 期待 header 内容不要被解析到 body,body 能正常就好。
赞
0
收藏
提问
分享
讨论
建议
公告
开发框架
CodeGalaxy
登录
后参与评论
评论
2020-04-29
鲁飞
如果你是压测情况下输出在控制台中的话,打印混乱是正常的,多进程打日志因为没锁会串。 请提供最简复现代码,或者尝试升级后再试。
赞
0
回复
2020-04-29
Pear
回复
鲁飞
谢谢回复,可能你没有仔细看,打印乱序是可以排除的,因为 ``` [“statusCode”]=> int(100) [“headers”]=> NULL [“set_cookie_headers”]=> NULL [“cookies”]=> NULL [“body”]=> string(253) “HTTP/1.1 200 OK Date: Tue, 28 Apr 2020 11:04:14 GMT Content-Type: application/json; charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive Cache-Control: max-age=0 Access-Control-Allow-Origin: * 1d {“code”:0,”msg”:””,”data”:””} 0 “ } ``` 我先尝试升级,如果还是不行,那我尝试提供复现代码(但是可能有点困难,不知道和请求的服务器有没有关系)
赞
0
回复
2020-04-29
Pear
回复
鲁飞
解决了,带了头 `Expect: 100-Continue`,可能是对方服务器没有响应这个 continue 请求,但不知道为啥影响了后面的解包
赞
0
回复