swoole-src
swoole-src copied to clipboard
Error WARNING ReactorEpoll::add()
I encountered an issue when using a coroutine to send data to AWS SNS within my application. The error occurs at runtime with the following message:
WARNING ReactorEpoll::add(): failed to add events[fd=26#0, type=27, events=512], Error: Bad file descriptor[9]
This happens when executing the coroutine using co(function () { ... })
Environment Details:
I have the same problem too
Any update?
Hi. Please tell me what framework you are using.
If possible, could you provide a reproducible code example?
Thank you
@jilcimar @ElielFC @b-bianca
You need to provide a code example that can reproduce this issue. Additionally, if you are using extensions such as gRPC, there may be compatibility issues with Swoole.
Hi. Please tell me what framework you are using. If possible, could you provide a reproducible code example? Thank you @jilcimar @ElielFC @b-bianca
The framework used is Hyperf, and here is the code snippet showing an example of the coroutine usage that is causing the issue:
co(function () use ($parameter1, $parameter2, $parameter3, $parameter4, $parameter5) {
try {
$client = new SnsClient(config("notification." . config('notification.requests_logs.config')));
$message = [
//content
];
$client->publish([
'TopicArn' => config('notification.requests_logs.topic'),
'Subject' => 'Requests Logs',
'Message' => json_encode($message),
]);
} catch (Throwable $e) {
logger()->error("{$e->getMessage()}, trace: {$e->getTraceAsString()}");
}
});
I had to hide the contents of the $message array for confidentiality reasons.
Could you please run php --ri curl? @jilcimar
@jilcimar Please provide the full namespace and Composer package name.
I cannot replicate your issue. My curl version is 7.81.0, and my PHP version is 8.2.23.
I cannot replicate your issue. My curl version is 7.81.0, and my PHP version is 8.2.23.
@matyhtf My curl version is 8.12.1, and my PHP version is 8.3.15 .
Guzzle version is "guzzlehttp/guzzle": "^7.9" - 7.9.2
AWS SDK version is "aws/aws-sdk-php": "^3.324" - 3.339.14
It only happens in the production environment and when the request volume is high
@jilcimar Please test with the latest code from the GitHub master branch, setting the print_backtrace_on_error option to true. This option will print the call stack when an unknown error occurs. This is an unknown error, and I cannot currently think of the circumstances under which this issue might arise.
print_backtrace_on_error
@matyhtf This option is for enable on Swoole Server or swoole.ini file?
@iamrafaelmelo
This is a global option that can be set as follows:
\Swoole\Coroutine::set(['print_backtrace_on_error' => true]);
// or
swoole_async_set(['print_backtrace_on_error' => true]);
Thank you for your bug report. We need more information to analyze the issue. What impacts arise after this error log appears?
I recommend installing the Boost Stacktrace library before compiling the new version of swoole.
sudo apt install libboost-stacktrace-dev
This is a global option that can be set as follows:
\Swoole\Coroutine::set(['print_backtrace_on_error' => true]); // or swoole_async_set(['print_backtrace_on_error' => true]); Thank you for your bug report. We need more information to analyze the issue. What impacts arise after this error log appears?
Sorry for long time without response (holidays), i'm deploying the service with this flag enable today, when i have some tests, will be back here.
@matyhtf
I "enabled" these settings, but without success, maybe because Hyperf rewrote the settings. The most I could see was the new log format, that's all.
[2025-04-22 16:47:55 *12.3] WARNING ReactorEpoll::add() (ERRNO 801): failed to add events[fd=31#3, type=27, events=512]
PS: we are using the master Swoole
@iamrafaelmelo Please execute the following command to update swoole-src and recompile, ensuring that the cache is cleared.
git pull
phpize
./configure [your options]
make clean
make -j 8
make install
Check the output of php --ri swoole or look at config.h to see if boost stacktrace or execinfo.h is enabled.
@matyhtf I achieve install boost-dev on Alpine Linux, and works, on enable print_backtrace_on_error option we have been this results
Alpine
- We are using the latest version (3.21)
Swoole informations
PHP version and extensions
Any updates about this?
I have encountered the same issue. Luckily, I was able to reproduce it in my local environment. Here is a minimal example to reproduce the error.
Steps to reproduce:
docker-compose updocker run --rm -i --add-host=host.docker.internal:host-gateway grafana/k6 run - < test.js
Error WARNING ReactorEpoll::add() occurs in logs of service-a
docker run --rm -i --add-host=host.docker.internal:host-gateway grafana/k6 run - < test.js
Yes, reproduced locally:
I have encountered the same issue. Luckily, I was able to reproduce it in my local environment. Here is a minimal example to reproduce the error.
Steps to reproduce:
docker-compose updocker run --rm -i --add-host=host.docker.internal:host-gateway grafana/k6 run - < test.js
Error WARNING ReactorEpoll::add()occurs in logs of service-a
OK, I will try to reproduce this problem locally recently.
@MartinKrizan @hydrapolic
Fixed. This is caused by two reasons.
The first problem is that the bottom layer of swoole supports both PHP7 and PHP8 through compatible code. Only std:: unordered_map<CURL *, Handle *> handle_buckets can store private data using curl_easy * pointer as the hashmap of the key. The latest PHP8 code does not use the CURLOPT_PRIVATE of libcurl for the implementation of the CURLOPT_PRIVATE option, but is implemented at the php level. This allows the underlying layer to use the CURLOPT_PRIVATE of libcurl to store the Handle pointer.
The second problem is that there is a problem with the handling of the curl handle of keepalive. When curl multi remove the handle, must clear all socket fds of curl_easy. Otherwise, incorrect event listening will occur
Thanks @matyhtf for fixing this, appreciated!
Just tested with swoole-master (https://github.com/swoole/swoole-src/commit/8a56a771435711223baaff01266360a73e913f2d) and the warnings are gone 👍