Skip to content

Commit

Permalink
Fix memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
Meldiron committed Oct 11, 2023
1 parent e34ed9c commit c68f74e
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Http/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Utopia\Http;

use Throwable;

class Http
{
/**
Expand Down Expand Up @@ -563,7 +565,15 @@ public static function onRequest(): Hook

public function start()
{
$this->server->onRequest(fn ($request, $response, $context) => $this->run($request, $response, $context));
$this->server->onRequest(function ($request, $response, $context) {
try {
$this->run($request, $response, $context);
} finally {
if(isset(self::$resourcesCallbacks[$context])) {
unset(self::$resourcesCallbacks[$context]);
}
}
});
$this->server->onStart(function ($server) {
$this->resources['utopia'] ??= [];
$this->resources['utopia']['server'] = $server;
Expand Down

0 comments on commit c68f74e

Please sign in to comment.