Baldinof / roadrunner-bundle

A RoadRunner worker integrated in your Symfony app
MIT License
270 stars 48 forks source link

Blackfire integration not working #89

Closed KakakuCZ closed 1 year ago

KakakuCZ commented 2 years ago

Hello, I used roadrunner blackfire integration from your bundle and when i'm trying to profile any page, I have problem with session. It throws an error "ErrorException: session_start(): user session functions not defined in .../.../vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php:154".

I have no idea, what should cause this type of error. I suppose, that php extension wraps whole project in some "box", which doesn't allow me to call session. Why? I don't know.

I have installed php extension for blackfire (php.ini) and blackfire-php-sdk. If I run blackrire on FPM, everything works fine, so it shouldn't be problem in Symfony. Can you help me, what should be problem?

This is log of profiling. There are two requests (is that right?). First is OK, but second falls on session_start();

php-rr_1               | 2022-09-22T23:22:02.743+0200   INFO    http            http log        {"status": 200, "method": "GET", "URI": "http://demo.test/rr/health", "remote_address": "172.18.0.1", "start": "2022-09-22T23:22:02.671+0200", "elapsed": "72.037842ms"}
php-rr_1               | 2022-09-22T23:22:02.881+0200   INFO    http            http log        {"status": 200, "method": "GET", "URI": "http://demo.test/rr/health", "remote_address": "172.18.0.1", "start": "2022-09-22T23:22:02.674+0200", "elapsed": "206.77573ms"}
php-rr_1               | [2022-09-22 23-22-03] ErrorException: session_start(): user session functions not defined in /var/www/demo-test/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php:154  @  CLI (PID: 26): bin/worker.php  @@  02bb85b74b
php-rr_1               | 
php-rr_1               | network error, worker will be restarted        {"reason": "network", "pid": 26, "internal_event_name": "EventWorkerError", "error": "sync_worker_exec: Network:\n\tsync_worker_exec_payload: EOF"}
php-rr_1               | 2022-09-22T23:22:03.003+0200   ERROR   http            execute {"start": "2022-09-22T23:22:02.890+0200", "elapsed": "113.57497ms", "error": "sync_worker_exec: Network:\n\tsync_worker_exec_payload: EOF"}
php-rr_1               | worker stopped {"internal_event_name": "EventWorkerWaitExit", "error": "signal: killed; process_wait: signal: killed", "errorCauses": [{"error": "signal: killed"}, {"error": "process_wait: signal: killed"}]}
php-rr_1               | worker is allocated    {"pid": 34, "internal_event_name": "EventWorkerConstruct"}

Edit: I tried to make a minimum version of your code (without any sessions, etc.). I used only minimum code (HttpFoundationWorker and your implementation of Blackfire).

Same error :(

$kernel = new AppKernel("dev", true);
$relay = new SocketRelay("/var/run/rr.sock", null, SocketRelay::SOCK_UNIX);
$worker = new HttpFoundationWorker(new HttpWorker(new Spiral\RoadRunner\Worker($relay)));
$kernel->boot();
while ($request = $worker->waitRequest()) {
    if ($request->headers->has('x-blackfire-query')) {
        $query = $request->headers->get('x-blackfire-query');
        $blackfireProbe = new \BlackfireProbe($query);
        $blackfireProbe->enable();
    } else {
        $blackfireProbe = null;
    }

    $response = $kernel->handle($request);

    if ($blackfireProbe !== null && $blackfireProbe->isEnabled()) {
        $blackfireProbe->close();
        [$probeHeaderName, $probeHeaderValue] = explode(':', $blackfireProbe->getResponseLine(), 2);
        $response->headers->set('x-'.$probeHeaderName, trim($probeHeaderValue));
    }
    $worker->respond($response);
}

Symfony Controller (FPM works fine, RR on this endpoint works fine until i turn on profiling by extension):

/**
 * @Route(service=RoadRunnerHealthController::class)
 */
class RoadRunnerHealthController {
    /**
     * @Route("/rr/health", name="route.demo.rr.health")
     * @Method("GET")
     */
    public function actionHealthcheck(): Response {
        return new Response("<html><body>Health: OK</body></html>");
    }
}
Baldinof commented 2 years ago

Hi, thank you for using this package :)

It's working on my side on a fresh symfony project.

Can you show me your php version and the version of the packages you are using ?

$ composer show | grep -e 'symfony' -e 'roadrunner'
$ php -v
KakakuCZ commented 2 years ago

PHP 7.4.27 Symfony: 3.4.47 RR: 2.1.0

Baldinof commented 2 years ago

Thanks, and what's the version of the baldinof/roadrunner-bundle package?

KakakuCZ commented 2 years ago

2.2.3

Baldinof commented 2 years ago

👍 I'll try to have a look

Baldinof commented 2 years ago

This package does not support Symfony 3.4, how did you manage to install this package?

Are you sure sessions are enabled in your php.ini for CLI? What's your output of php -r 'var_dump(extension_loaded("session"));'?