Fixed topic gc bug

This commit is contained in:
Chris 2024-03-11 01:40:05 +01:00
parent c31c55fafd
commit 2cbc41d29e
5 changed files with 8 additions and 4 deletions

View File

@ -13,8 +13,8 @@ phar: ## Build .phar using pharlite
git clone $(REPODIR) $(BUILDDIR) && \ git clone $(REPODIR) $(BUILDDIR) && \
cd $(BUILDDIR) && \ cd $(BUILDDIR) && \
composer install --no-dev && \ composer install --no-dev && \
pharlite && \ pharlite
mv $(BUILDDIR)/*.phar . && \ mv $(BUILDDIR)/*.phar $(REPODIR) && \
rm -rf $(BUILDDIR) rm -rf $(BUILDDIR)
.PHONY: phpstan .PHONY: phpstan

View File

@ -43,7 +43,7 @@ $ ./mercureact.phar -c mercureact.conf
* [x] Subscription/Topic manager * [x] Subscription/Topic manager
* [x] Unify distribution * [x] Unify distribution
* [ ] Enumerate subscriptions and topics * [ ] Enumerate subscriptions and topics
* [ ] Publish events * [x] Publish events
* [x] Server-Side Events distributor * [x] Server-Side Events distributor
* [x] Distribute events over SSE * [x] Distribute events over SSE
* [ ] WebSocket distributor * [ ] WebSocket distributor

View File

@ -69,7 +69,7 @@ class TopicManager
$this->topics, $this->topics,
function (Topic $topic) { function (Topic $topic) {
$topic->garbageCollect(); $topic->garbageCollect();
return ($topic->getHistorySize() > 0 && $topic->getSubscriberCount() > 0) || ($topic->getAge() < 60); return ($topic->getHistorySize() > 0 || $topic->getSubscriberCount() > 0) || ($topic->getAge() < 60);
} }
); );
} }

View File

@ -55,6 +55,7 @@ class ResponseMiddleware
if ($t instanceof SecurityException) { if ($t instanceof SecurityException) {
return Response::plaintext("Access Denied")->withStatus(Response::STATUS_UNAUTHORIZED); return Response::plaintext("Access Denied")->withStatus(Response::STATUS_UNAUTHORIZED);
} }
$this->logger->warning(get_class($t).": ".$t->getMessage(), [ 'file'=>$t->getFile(), 'line'=>$t->getLine() ]);
return Response::plaintext("500: Internal Server Error (".$t->getMessage().")\n")->withStatus(500); return Response::plaintext("500: Internal Server Error (".$t->getMessage().")\n")->withStatus(500);
} }
)->then( )->then(

View File

@ -54,6 +54,9 @@ class Server
$this->logger = $this->createLogger(); $this->logger = $this->createLogger();
$this->topicManager = new TopicManager(); $this->topicManager = new TopicManager();
$this->loop->addPeriodicTimer(30, function () {
$this->topicManager->garbageCollect();
});
$this->webSocketClients = new SplObjectStorage(); $this->webSocketClients = new SplObjectStorage();