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

TopicPeriodicTimer only registered for one Topic, wrongly cleared if any one Topic has zero connections #476

Open
Androbin opened this issue Dec 15, 2022 · 1 comment

Comments

@Androbin
Copy link
Contributor

Description

The function TopicPeriodicTimerInterface::registerPeriodicTimer takes a Topic parameter, but once the first Topic registers a timer, it is not called for any additional Topic. Furthermore, if any one Topic has zero connections, any and all timers registered within the TopicInterface are cleared.

Example code

<?php

namespace App\Websocket\Topic;

use Gos\Bundle\WebSocketBundle\Topic\TopicPeriodicTimerInterface;
use Gos\Bundle\WebSocketBundle\Topic\TopicPeriodicTimerTrait;
use Ratchet\Wamp\Topic;

class AcmePeriodicTopic extends AcmeTopic implements TopicPeriodicTimerInterface
{
    use TopicPeriodicTimerTrait;

    public function registerPeriodicTimer(Topic $topic): void
    {
        // Adds the periodic timer the first time a client connects to the topic
        $this->periodicTimer->addPeriodicTimer(
            $this,
            'hello',
            300,
            function () use ($topic) {
                $topic->broadcast('Hello world');
            }
        );
    }

    /**
     * Name of the topic.
     */
    public function getName(): string
    {
        return 'acme.periodic.topic';
    }
}

Steps

  • client 1 subscribes to acme/foo
  • timer is registered for acme/foo
  • client 2 subscribes to acme/bar
  • timer isn't registered for acme/bar
  • client 2 unsubscribes from acme/bar
  • timer is cleared for acme/foo
@Androbin
Copy link
Contributor Author

The root problem is that TopicPeriodicTimer::addPeriodicTimer doesn't take the Topic passed to TopicPeriodicTimerInterface::registerPeriodicTimer as a parameter.

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