Skip to content
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

Channel issue due to package_length. Another reason #303

Open
quietasice opened this issue Mar 26, 2024 · 0 comments
Open

Channel issue due to package_length. Another reason #303

quietasice opened this issue Mar 26, 2024 · 0 comments

Comments

@quietasice
Copy link

quietasice commented Mar 26, 2024

Hi @walkor.
First of all thank you so much for your socket.io port.

I'm getting a lot of errors Error package. package_length= and started to investigate it. I found your posts about the client sending the wrong packet. This could be the reason, but I found another case. Im getting errors when worker's clients cross 7-10k connections.

To be able to send a message to a specific connection, you defined each "sid" as a room.
https://github.com/walkor/phpsocket.io/blob/master/src/Socket.php#L246

public function join($room)
{
    if (! $this->connected) {
        return $this;
    }
    if (isset($this->rooms[$room])) {
        return $this;
    }
    $this->adapter->add($this->id, $room);
    $this->rooms[$room] = $room;
    return $this;
    }

and the adapter will subscribe to the "sid\room"
https://github.com/walkor/phpsocket.io/blob/master/src/ChannelAdapter.php#L33

public function add($id, $room)
{
    $this->sids[$id][$room] = true;
    $this->rooms[$room][$id] = true;
    $channel = "socket.io#/#$room#";
    \Channel\Client::subscribe($channel);
}

Each time a client establishes a connection, a message to the channel includes all worker's SIDs
https://github.com/walkor/channel/blob/master/src/Client.php#L199

public static function onRemoteConnect()
{
    $all_event_names = array_keys(self::$_events);
    if($all_event_names)
    {
        self::subscribe($all_event_names);
    }
    self::clearTimer();

    if (self::$onConnect) {
        call_user_func(Client::$onConnect);
    }
}

https://github.com/walkor/channel/blob/master/src/Client.php#L250

public static function subscribe($events)
{
    $events = (array)$events;
    self::send(array('type' => 'subscribe', 'channels'=>$events));
    foreach ($events as $event) {
        if(!isset(self::$_events[$event])) {
            self::$_events[$event] = null;
        }
    }
}

similar to this
a:2:{s:4:"type";s:9:"subscribe";s:8:"channels";a:4:{i:0;s:12:"socket.io#/#";i:1;s:37:"socket.io#/#c66cbafbbf80d94105ab5045#";i:2;s:37:"socket.io#/#44dfbbfbbf80d941048015df#";i:3

which will definitely start hitting the packet size limit sooner or later.

Is it make sense for you? just want let people know, who will get same errors that the reason may not be due to wrong packet, but to a simpler reason of growth

This problem can be solved by adding more nodes to reduce the average number of connections per node, but this is likely a workaround. I think I'll look into Redis as a channel adapter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant