walkor / walkor/workerman

[BUG] eventLoop设为Swoole,当Swoole版本为6.x在非iouring下响应大文件异常的BUG

Open
#1,106 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
PHP
Stars
11.6k
Forks
2.2k
Avg merge
11h 30m
Merged PRs (30d)
3

Description

Please answer these questions before submitting your issue.

1. What did you do? If possible, provide a simple script for reproducing the error.

- Workerman设置Swoole作为事件循环
- Swoole版本为6.X
- 不开启iouring
- 响应一个大图片

满足以上条件后,会复现这个BUG

复现代码如下:
```
eventLoop = Swoole::class;

$http_worker->onMessage = function (TcpConnection $connection, Request $request) {
$response = (new Response())->withFile('./image_8M.png');
$connection->send($response);
};

Worker::runAll();
```

经调试,我猜可能和`src/Protocols/Http.php`的第279行注册的`onBufferDrain`事件有关,因为这个事件被并发执行了,导致同一时间`$doWrite()`执行了多次。把249行的注释掉就没问题了。但是这个行为不合规,缓冲区功能将失效。

目前已测试过开启iouring是正常的,另外使用Select作为EventLoop也正常。

2. What did you expect to see?

浏览器正常响应完整的图片

3. What did you see instead?

浏览器只响应了一半的图片

![Image](https://github.com/user-attachments/assets/365ef2fc-0a27-4107-a63d-cf97f637f481)

4. What version of Workerman are you using (show your `composer info`)?

```
workerman/coroutine 1.1.3 Workerman coroutine
workerman/webman-framework 2.1.2 High performance HTTP Service Framework.
workerman/workerman 5.1.3 An asynchronous event driven PHP framework for easily building fast, scalable network applications.
```

5. What is your machine environment used (show your `uname -a` & `php -v` & `php -m`) ?

```
(base) root@MoxyuPC:/www/wwwroot/valorix/server-api# uname -a
Linux MoxyuPC 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 GNU/Linux

(base) root@MoxyuPC:/www/wwwroot/valorix/server-api# php -v
PHP 8.4.7 (cli) (built: May 9 2025 10:58:14) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.7, Copyright (c) Zend Technologies

(base) root@MoxyuPC:/www/wwwroot/valorix/server-api# php -m
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
fileinfo
filter
ftp
gd
gettext
hash
iconv
igbinary
intl
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
random
redis
Reflection
session
shmop
SimpleXML
soap
sockets
sodium
SPL
sqlite3
standard
swoole
sysvsem
tokenizer
xml
xmlreader
xmlwriter
zip
zlib

[Zend Modules]
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.