Comments (9)
It is possible that there is an issue with the data being sent, indicating an error in receiving a packet of length 50, and the custom function is unable to handle it, resulting in a return of -1 and closing the connection. Check if an exception is being thrown.
from swoole-src.
I checked this and the exception does not occur, when there are many packages incoming that are not valid and we return -1, after some time it causes the workers to restart.
Like this:
[2024-04-23 11:58:10 #18985.3] WARNING Protocol::recv_with_length_protocol() (ERRNO 1204): received 50 bytes of malformed data from the client[172.19.0.2:39558]
[2024-04-23 11:58:10 #18985.3] WARNING Protocol::recv_with_length_protocol() (ERRNO 1204): received 254 bytes of malformed data from the client[172.19.0.2:39560]
[2024-04-23 11:58:10 #18985.3] WARNING Protocol::recv_with_length_protocol() (ERRNO 1204): received 50 bytes of malformed data from the client[172.19.0.2:39562]
[2024-04-23 11:58:10 #18985.3] WARNING Protocol::recv_with_length_protocol() (ERRNO 1204): received 50 bytes of malformed data from the client[172.19.0.2:39564]
[2024-04-23 11:58:10 #18985.3] WARNING Protocol::recv_with_length_protocol() (ERRNO 1204): received 50 bytes of malformed data from the client[172.19.0.2:39566]
[2024-04-23 11:58:10 #18985.3] WARNING Protocol::recv_with_length_protocol() (ERRNO 1204): received 50 bytes of malformed data from the client[172.19.0.2:39568]
[2024-04-23 11:58:10 #18985.3] WARNING Protocol::recv_with_length_protocol() (ERRNO 1204): received 254 bytes of malformed data from the client[172.19.0.2:39570]
[2024-04-23 11:58:10 #18985.3] WARNING Protocol::recv_with_length_protocol() (ERRNO 1204): received 254 bytes of malformed data from the client[172.19.0.2:39572]
[2024-04-23 11:58:10 #18985.3] WARNING Protocol::recv_with_length_protocol() (ERRNO 1204): received 50 bytes of malformed data from the client[172.19.0.2:39574]
[2024-04-23 11:58:10 #18985.3] WARNING Protocol::recv_with_length_protocol() (ERRNO 1204): received 254 bytes of malformed data from the client[172.19.0.2:39576]
[2024-04-23 11:58:10 #18985.3] WARNING Protocol::recv_with_length_protocol() (ERRNO 1204): received 50 bytes of malformed data from the client[172.19.0.2:39578]
[2024-04-23 11:58:10 #18985.3] WARNING Protocol::recv_with_length_protocol() (ERRNO 1204): received 50 bytes of malformed data from the client[172.19.0.2:39580]
[2024-04-23 11:58:10 #18985.3] WARNING Protocol::recv_with_length_protocol() (ERRNO 1204): received 254 bytes of malformed data from the client[172.19.0.2:39582]
[2024-04-23 11:58:10 #18985.3] WARNING Protocol::recv_with_length_protocol() (ERRNO 1204): received 254 bytes of malformed data from the client[172.19.0.2:39584]
[2024-04-23 11:58:10 #18985.3] WARNING Protocol::recv_with_length_protocol() (ERRNO 1204): received 50 bytes of malformed data from the client[172.19.0.2:39586]
[2024-04-23 11:58:11 #18985.3] WARNING Protocol::recv_with_length_protocol() (ERRNO 1204): received 50 bytes of malformed data from the client[172.19.0.2:39592]
[2024-04-23 11:58:11 #18985.3] WARNING Protocol::recv_with_length_protocol() (ERRNO 1204): received 50 bytes of malformed data from the client[172.19.0.2:39594]
WORKER: 2 IS EXIT
WORKER: 0 IS EXIT
WORKER: 4 IS EXIT
WORKER: 2 IS EXIT
WORKER: 0 IS EXIT
WORKER: 4 IS EXIT
WORKER: 6 IS EXIT
WORKER: 6 IS EXIT
WORKER: 8 IS EXIT
WORKER: 1 IS EXIT
WORKER: 8 IS EXIT
WORKER: 1 IS EXIT
WORKER: 7 IS EXIT
WORKER: 7 IS EXIT
WORKER: 5 IS EXIT
WORKER: 5 IS EXIT
WORKER: 3 IS EXIT
WORKER: 3 IS EXIT
WORKER: 9 IS EXIT
WORKER: 9 IS EXIT
WORKER: 0 IS EXIT
WORKER: 1 IS EXIT
WORKER: 2 IS EXIT
Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)
Note: I run this server with 10 workers
from swoole-src.
Do you have the configuration for "max_request" set?
from swoole-src.
No, I just used these configs:
$server->set([
// Server
'worker_num' => 10,
// Tcp server
'heartbeat_idle_time' => 510,
'heartbeat_check_interval' => 10,
// TCP Parser
'open_length_check' => true,
'package_max_length' => 81920,
'package_length_func' => function ($data) {
//...
},
// Coroutine
'enable_coroutine' => true,
'hook_flags' => SWOOLE_HOOK_ALL,
'max_coroutine' => 200000,
]);
from swoole-src.
Can anyone help me with this issues?
from swoole-src.
I checked my codes and tried to see when exactly this error occurs
Finally, I came to the conclusion that when I use Timer::tick outside of Workers, I get this error
I had to use "APCu" instead of "package_length_func" 🥲
from swoole-src.
Could you please provide the code on how to use Swoole\Timer
?
from swoole-src.
Explanation of the PHP code:
HamidServer class:
This class is responsible for creating and running a Swoole server.
class HamidServer
{
public $server;
public function __construct(string $host, int $port)
{
$this->server = new Server($host, $port, SWOOLE_PROCESS, SWOOLE_SOCK_TCP);
}
public function start(): void
{
$this->server->start();
}
}
SystemStatus class:
This class is responsible for collecting system statistics and displaying them through an HTTP server.
$prometheusServer = $server->addlistener('127.0.0.1', 8889, SWOOLE_SOCK_TCP);
$prometheusServer->set([
'open_http_protocol' => true, // Enable HTTP protocol parsing
]);
$prometheusServer->on('request', [$this, 'on_request']);
Creating SystemStatus class in HamidServer constructor:
class HamidServer
{
// ...
public $systemStatus;
public function __construct(string $host, int $port)
{
// ...
$this->systemStatus = new SystemStatus($this);
}
// ...
}
SystemStatus class constructor:
In this section, Timer::tick
is called and the necessary information for display in the output is stored.
class SystemStatus
{
private $hamidContext;
public function __construct(HamidServer $hamidContext)
{
$this->hamidContext = $hamidContext;
Timer::tick(5000, function() {
$serverState = $this->hamidContext->server->stats();
// ...
});
}
// ...
}
realMetric
method:
This method is called for each worker and performs similar tasks as the class constructor.
class SystemStatus
{
// ...
public function realMetric(int $workerId): void
{
Timer::tick(5000, function use ($workerId) {
// ...
});
}
// ...
}
Creating realMetric
in on_worker_start
:
class HamidServer
{
// ...
public function __construct(string $host, int $port)
{
// ...
$this->server->on('WorkerStart', [$this, 'on_worker_start']);
}
public function on_worker_start(Server $server, int $workerId): void
{
if (!$server->taskworker) {
$this->workerStatus->realMetric($workerId);
}
}
// ...
}
from swoole-src.
I came and used APCu function instead of package_length_func
Now I ran into a problem and that was that the workers are restarted automatically
When I go and see the error log, I get something like this
malloc(): unaligned tcache chunk detected
I guess it is because of using APCu
from swoole-src.
Related Issues (20)
- A bug occurred in Swoole-v5.1.2, please report it HOT 26
- PHP Startup Unable to load dynamic library 'swoole' HOT 2
- guzzlehttp在stream=true时,设置超时无效 HOT 5
- 协程被长时间挂起会导致内存大量增加 HOT 49
- windows swoole-cli-v4.8.13-cygwin-x64.zip 在windows上 run(function{}) 内的curl 问题 HOT 2
- 在 Swoole\Coroutine\Http\Server 中的 http server 使用 sendfile 在高并发时会导致 PHP 假死并且内存泄露 HOT 57
- 🪶 在 C++ 中,有提供了Socket sendfile的方法(zerocopy),可以不通过CPU去调度资源,避免重复拷贝两次DMZ(或者更多) HOT 15
- windows swoole-cli-v4.8.13-cygwin-x64 使用协程监听的Channel数据然后插入数据库,插入没几条就报错了! HOT 5
- syntax error near unexpected token `SQLITE,' HOT 4
- @swoole/library/ext/sockets.php(217) E_DEPRECATED:Creation of dynamic property Swoole\Coroutine\Socket::$__ext_sockets_nonblock is deprecated HOT 3
- MACOS M1 SIGRTMIN HOT 2
- swoole:5.1.2-php8.3 - Maximum call stack size of 8339456 bytes (zend.max_allowed_stack_size - zend.reserved_stack_size) reached. HOT 4
- 编译swoole所用libcurl头文件和PHP 8.3所用版本不同导致Segmentation fault HOT 5
- tracker现在没了吗 HOT 1
- swoole-cli 运行项目时如何使用xlswriter HOT 2
- 面向aop开发 HOT 4
- server.pid file is not created HOT 2
- free(): invalid pointer when curl support is on HOT 10
- Lines to stderr gets tangled
- WebSocket: After calling $webSockerServer->push() from within onMessage event, the WebSocket connection closes by calling onClose event. HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swoole-src.