Giter VIP home page Giter VIP logo

Comments (9)

NathanFreeman avatar NathanFreeman commented on July 18, 2024

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.

karevan avatar karevan commented on July 18, 2024

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.

NathanFreeman avatar NathanFreeman commented on July 18, 2024

Do you have the configuration for "max_request" set?

from swoole-src.

karevan avatar karevan commented on July 18, 2024

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.

karevan avatar karevan commented on July 18, 2024

Can anyone help me with this issues?

from swoole-src.

karevan avatar karevan commented on July 18, 2024

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.

NathanFreeman avatar NathanFreeman commented on July 18, 2024

Could you please provide the code on how to use Swoole\Timer?

from swoole-src.

karevan avatar karevan commented on July 18, 2024

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.

karevan avatar karevan commented on July 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.