symfony / panther

A browser testing and web crawling library for PHP and Symfony
MIT License
2.91k stars 213 forks source link

Could not start firefox. Exit code: 139 (Segmentation violation). #558

Open wanwin opened 2 years ago

wanwin commented 2 years ago

Hi!

<?php
namespace App\Controller\Cursos\ContenidoCurso;

use App\Service\CursosDataAccess;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Panther\Client;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;

<?php
    namespace App\Controller\Cursos\ContenidoCurso;

    use App\Service\CursosDataAccess;
    use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
    use Symfony\Component\HttpFoundation\JsonResponse;
    use Symfony\Component\HttpFoundation\Request;
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\Panther\Client;
    use Symfony\Component\Routing\Annotation\Route;
    use Symfony\Component\Security\Core\Exception\AccessDeniedException;

    if (!$request->request->has('course_id') || !$request->request->has('url')){
        throw new AccessDeniedException();
    }else{
        $course_id = $request->request->get('course_id');
        $url = $request->request->get('url');
        if (
            is_null($course_id)
         || is_null($url)
         || $dataAccess->getCurso($course_id)["cod_empresa"] != $this->getUser()->getCodEmpresa()
         || !$this->isGranted('ROLE_GESTOR')) {
            throw new AccessDeniedException();
        }
    }
    $client = Client::createFirefoxClient('assets/drivers/geckodriver', null, ['capabilities' => ['acceptInsecureCerts' => true]]);
    $crawler = $client->request('GET', $url);
    $id_array = array();
    $crawler->filter('a.overview-list-item__link')->each(function ($node) use(&$id_array) {
        $module_id = $node->attr('href');
        $module_id = explode('/', $module_id);
        $id_array[] = $module_id[count($module_id) - 1];
    });
    $titles_array = array();
    $crawler->filter('div.overview-list-item__title')->each(function ($node) use(&$titles_array) {
        $titles_array[] = $node->text();
    });
    for ($i = 0; $i < count($id_array); $i++){
        $dataAccess->createModulo($course_id, $titles_array[$i], "", $id_array[$i]);
    }
    $success = true;
    $response = array(
        'success' => $success,
        'content' => $success ? $this->renderView('Cursos/panels/modulos.html.twig', [
            "data" => [
                        "curso" => $dataAccess->getCurso($course_id),
                        "modulos" => $dataAccess->getModulos($course_id)
                    ]
        ]) : null,
    );
    return new JsonResponse(json_encode($response));
?>

When I run the previous code, I'm getting the error mentioned in the title that comes from vendor/symfony/panther/src/ProcessManager/WebServerReadinessProbeTrait.php -more specifically from the condition "if (Process::STATUS_TERMINATED === $status)" in line 52-.

The bin file, geckodriver (version 0.31.0), has its permissions set to 777 because initially I was getting a "Permission denied" error and when I specify a wrong route the error tells me that, so I don't think that the problem is related to the file. I have tried too to change the driver from geckodriver to chromedriver and the used method to createFirefoxClient to createChromeClient, but I'm getting the same error.

I'm starting to think that this problem is related with the server, but if you know what could be its cause I think that I will solve this problem more easily.

Thank you for your help!

Fabrn commented 5 months ago

Hello !

I know it has been a while and sadly this issue never received any comment, so here I am !

I am encountering the same issue right now. Like the exact same. I have no clue how to solve it and the internet is not helping very much right now.

If you or anyone who see this message have the answer, this would be majestic !