-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Memory leak if try to write in close socket #93
Comments
Is it expected behavoir? ) |
From a first look, this behavior doesn't look like expected behavior. |
Is it still actual for the third version? |
I can confirm: It's not a problem anymore. I adapted the for v3 like this use Revolt\EventLoop;
use function Amp\Socket\listen;
require_once(__DIR__ . '/vendor/autoload.php');
Amp\async(function () {
$uri = "tcp://127.0.0.1:1337";
EventLoop::repeat(10, function () {
echo 'Counters: '. Test::$constructInc . ' - ' . Test::$destructInc . PHP_EOL;
echo 'Memory: ' . round(memory_get_usage() / 1024, 2) . ' KB' . PHP_EOL;
});
$server = listen($uri);
while ($socket = $server->accept()) {
$obj = new Test($socket);
$obj->run();
unset($obj);
}
})->await();
class Test
{
public static int $constructInc = 0;
public static int $destructInc = 0;
public string $content;
public function __construct(private \Amp\Socket\ResourceSocket $socket)
{
$this->content = str_repeat('a', 2048);
self::$constructInc++;
}
public function __destruct()
{
echo 'destruct' . PHP_EOL;
self::$destructInc++;
}
public function run()
{
Amp\async(function () {
try {
$this->socket->close();
$this->socket->write('test');
} catch (Throwable $e) {
echo 'catch exception' . PHP_EOL;
}
});
}
} And i didn't have any leak:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example
Run script and try to connect by telnet several times
Result in console
Test
instances only created but not destructed. Memory consumption increasesIf change
vendor\amphp\byte-stream\lib\ResourceOutputStream.php:177
fromto
got these results
Instances destructed, memory is stable.
PHP 8.1, amp 2.6.2, amphp/socket 1.2.0.
The text was updated successfully, but these errors were encountered: