-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
ssl websocket 在微信小程序手机端连续发送数据不能立即接收 #5584
Comments
这个看起来像是微信端发送了一部分数据,然后等待websocket服务器发送响应过来才会继续发送下一部分的数据。或者是服务端这边还在等微信端发送完整的数据过来。 |
抓个包看看,换一下你的网卡和端口号
复现以后把 mqtt.pcap 提上来 |
|
你这个少 connect 包,就去发布订阅了 |
已经注释掉了订阅相关 |
你已经实现了 connect ack,这个代码不是复现代码吧? |
mqtt.js 发送的连接包会分成多次websocket包发送, connect ack在这里显示的不准,connect ack应该是服务器发出,但是这里的方向反了。Src: 192.168.1.239是手机,Dst: 192.168.100.51是服务器。手机端发送连接超过5秒没有回应就会关闭连接,3秒后重新连接,从网卡收到数据时间来看手机发送是没有问题的。抓包用的是正常的服务器和手机端的mqtt.js。为了排除干扰方便测试,上面提供的测试代码也能模拟出问题情况。目前卡在receive from 1:MQTT,4d515454,这里。经过初步测试这里只要是3到7个字节就会卡住,试过2个或者8个字节(或以上)就不卡,或者前面少发一次websocket数据也不会卡。不用ssl也不卡,没有地方报错,唯一报错就是服务器收到完整连接报文时要回connect ack,但这个时候连接是已经关闭了。 |
没有用ssl会有这个问题吗 |
我早上没 ssl 测试,没问题。 |
没有ssl没问题,用Nginx代理也正常。有证书的情况下,电脑端微信开发者工具上,或者其他的mqtt工具都没问题。就手机上有问题。安卓、iPhone都一样 |
发生问题的场景是:在微信小程序手机端使用mqtt.js连接swoole websocket服务器,发送连接报文时卡住,卡在MQTT那个位置,等到前端关闭连接,才会一起收到数据。通过Nginx代理swoole可以正常接收。已排除手机端问题,排除SSL证书问题,尝试过不同的Swoole版本问题依旧。用电脑端的其他工具测试均正常,问题目前只出在微信手机端。
test.php内容如下:
以下内容是在微信小程序手机端模拟 mqtt.js 的连接报文连续发送数据,代码是微信小程序页面的js文件
正常应该是立即收到数据打印
server: handshake success with fd1
receive from 1:,10,opcode:2,fin:1
receive from 1:,1d,opcode:2,fin:1
receive from 1:,0004,opcode:2,fin:1
receive from 1:MQTT,4d515454,opcode:2,fin:1
receive from 1:,04,opcode:2,fin:1
receive from 1:,00,opcode:2,fin:1
receive from 1:<,003c,opcode:2,fin:1
receive from 1:,0011,opcode:2,fin:1
receive from 1:mqtt_1f8b549f69e1,6d7174745f316638623534396636396531,opcode:2,fin:1
立即收到打印的内容
server: handshake success with fd1
receive from 1:,10,opcode:2,fin:1
receive from 1:,1d,opcode:2,fin:1
receive from 1:,0004,opcode:2,fin:1
receive from 1:MQTT,4d515454,opcode:2,fin:1
到这里卡住
等前端关闭连接才打印
receive from 1:,04,opcode:2,fin:1
receive from 1:,00,opcode:2,fin:1
receive from 1:<,003c,opcode:2,fin:1
receive from 1:,0011,opcode:2,fin:1
receive from 1:mqtt_1f8b549f69e1,6d7174745f316638623534396636396531,opcode:2,fin:1
receive from 1:,,opcode:8,fin:1
client 1 closed
php --ri swoole
)?Swoole => enabled
Author => Swoole Team [email protected]
Version => 5.1.5
Built => Nov 15 2024 11:14:07
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
openssl => OpenSSL 1.1.1k FIPS 25 Mar 2021
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
zlib => 1.2.11
brotli => E16777222/D16777222
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_fiber_mock => Off => Off
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
uname -a
&php -v
&gcc -v
) ?Linux localhost.localdomain 4.19.91-25.1.an8.x86_64 #1 SMP Wed Dec 22 16:48:46 CST 2021 x86_64 x86_64 x86_64 GNU/Linux
PHP 8.2.25 (cli) (built: Nov 9 2024 21:58:33) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.25, Copyright (c) Zend Technologies
The text was updated successfully, but these errors were encountered: