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

[BUG] failed to read memory remote_address=0x64, errno=14 #429

Closed
vtsykun opened this issue Feb 18, 2024 · 1 comment · Fixed by #435
Closed

[BUG] failed to read memory remote_address=0x64, errno=14 #429

vtsykun opened this issue Feb 18, 2024 · 1 comment · Fixed by #435
Labels
bug Something isn't working Status: Verified

Comments

@vtsykun
Copy link

vtsykun commented Feb 18, 2024

Hi! Awesome project.

I've noticed a strange bug when tried to profile memory leak in project that use Fibers

Describe the bug

I got memory access error in this place read = $this->ffi->process_vm_readv(...). The function process_vm_readv returns with EFAULT 14 (Bad address) error code. Obviously that the passed address 0x64 is invalid, because usually the heap allocated with addresses 0x7fffffffffff-0x7f0000000000

sudo ./reli inspector:memory --pretty-print -p 114889 > mem_t0.json -vvv

In MemoryReader.php line 92:
                                                                           
  [Reli\Lib\Process\MemoryReader\MemoryReaderException (14)]               
  failed to read memory. target_pid=114889, remote_address=0x64, errno=14  
                                                                           

Exception trace:
  at /opt/progs/reli-prof/src/Lib/Process/MemoryReader/MemoryReader.php:92
 Reli\Lib\Process\MemoryReader\MemoryReader->read() at /opt/progs/reli-prof/src/Lib/Process/Pointer/RemoteProcessDereferencer.php:42
 Reli\Lib\Process\Pointer\RemoteProcessDereferencer->deref() at /opt/progs/reli-prof/src/Lib/PhpInternals/Types/Zend/ZendClassEntry.php:238
 Reli\Lib\PhpInternals\Types\Zend\ZendClassEntry->getStaticPropertyIterator() at /opt/progs/reli-prof/src/Lib/PhpProcessReader/PhpMemoryReader/MemoryLocationsCollector.php:1598
 Reli\Lib\PhpProcessReader\PhpMemoryReader\MemoryLocationsCollector->collectClassDefinition() at /opt/progs/reli-prof/src/Lib/PhpProcessReader/PhpMemoryReader/MemoryLocationsCollector.php:1524
 Reli\Lib\PhpProcessReader\PhpMemoryReader\MemoryLocationsCollector->collectClassDefinitionPointer() at /opt/progs/reli-prof/src/Lib/PhpProcessReader/PhpMemoryReader/MemoryLocationsCollector.php:1494
 Reli\Lib\PhpProcessReader\PhpMemoryReader\MemoryLocationsCollector->collectClassTable() at /opt/progs/reli-prof/src/Lib/PhpProcessReader/PhpMemoryReader/MemoryLocationsCollector.php:364
 Reli\Lib\PhpProcessReader\PhpMemoryReader\MemoryLocationsCollector->collectAll() at /opt/progs/reli-prof/src/Command/Inspector/MemoryCommand.php:95
 Reli\Command\Inspector\MemoryCommand->execute() at /opt/progs/reli-prof/vendor/symfony/console/Command/Command.php:326
 Symfony\Component\Console\Command\Command->run() at /opt/progs/reli-prof/vendor/symfony/console/Application.php:1063
 Symfony\Component\Console\Application->doRunCommand() at /opt/progs/reli-prof/vendor/symfony/console/Application.php:320
 Symfony\Component\Console\Application->doRun() at /opt/progs/reli-prof/vendor/symfony/console/Application.php:174
 Symfony\Component\Console\Application->run() at /opt/progs/reli-prof/reli:56

To Reproduce

  1. I am profiling this library https://github.com/danog/MadelineProto. Docs https://docs.madelineproto.xyz/docs/REQUIREMENTS.html

  2. Create and run script

<?php declare(strict_types=1);

use danog\MadelineProto\EventHandler\Attributes\Handler;
use danog\MadelineProto\EventHandler\Message;
use danog\MadelineProto\Settings;

require __DIR__.'/vendor/autoload.php';

class Handler1 extends \danog\MadelineProto\SimpleEventHandler
{
    #[Handler]
    public function handleMessage(Message $message): void
    {
        if ($_ENV['APP_DEBUG'] ?? false) {
            $event = json_decode(json_encode($message), true);
            $msg = json_encode($event, 448);
            echo "MSG---> $msg \n";
        }
    }
}


$settings = new Settings();
$info = $settings->getAppInfo();
!empty($_ENV['APP_API_HASH'])  ? $info->setApiHash($_ENV['APP_API_HASH']) : null;
!empty($_ENV['APP_API_ID']) ? $info->setApiId((int)$_ENV['APP_API_ID']) : null;

Handler1::startAndLoop('session.madeline', $settings);

Expected behavior
no exception

Execution Environment

  • OS: Ubuntu 22.04
  • PHP: 8.1.26
  • The version of Reli - master

Target Process

  • PHP: 8.1.26

UPD

Also I tried to use php-meminfo. But this library is not dump variables from suspended Fibers stack

@vtsykun vtsykun added the bug Something isn't working label Feb 18, 2024
@sj-i
Copy link
Member

sj-i commented Feb 20, 2024

@vtsykun
Hi, thanks for the good bug report!

Currently, I'm extremely busy, and don't have the bandwidth to look into this...

Apparently you have solved the problem you originally had with the modified version of php-meminfo. Brilliant job!.

Anyway, I'll take a closer look into this issue as soon as I can make the time.

to profile memory leak in project that use Fibers

FYI, also Reli doesn't support dumping the variables in suspended Fibers currently. As you know it is not too difficult, but I just don't have the time. We plan to support it in 0.12.0 or 0.13.0, the actual timeframe has not yet been decided though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Status: Verified
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants