【问题标题】:Injecting ServiceEntityRepository results in Segfault / nginx Bad gateway 502注入 ServiceEntityRepository 导致 Segfault / nginx Bad gateway 502
【发布时间】:2019-11-14 12:58:07
【问题描述】:

我们目前正在重写我们的代码库,进行此项更改:

// From
public function __construct(EntityManager $em){} // then use $this->em->getRepository(Example::class)

// To:
public function __construct(ExampleRepository $exampleRepo){} 

为了方便起见,我们将EntityReposity 更新为ServiceEntityRepository。这对单元测试有很大帮助,并且在大多数的情况下运行良好。

但在极少数情况下,我们会得到502 Bad Gateway,如果我们运行php bin/console 我们得到一个“分段错误”,这(至少在我们的理解中)意味着 C 刚刚中断。

在我们的研究中,我们创建了这样的理论:ServiceEntityRepository 加载 EntityManager,EM 加载 Repos,然后再加载 EM,等等。

我们的软件包目前根据各地的每个人的建议都是最新的,我希望这里有人能提出解决方案,现在或将来。那么,有人知道吗?


这个问题似乎相关:https://github.com/symfony/symfony/issues/30091

【问题讨论】:

    标签: php symfony segmentation-fault doctrine entitymanager


    【解决方案1】:

    现在我有一个“临时”解决方案,我将在此处发布,以便其他人在寻找解决方案时至少可以找到解决方法。如果我发现自己,我也会更新这个问题。

    错误似乎与主题中的说明相同。解决方案是退后一步。从构造函数中移除 Repository 注入并在方法中使用$this->em->getRepository(Example::class) 。以下将起作用,因为您仍在构造中加载 repo,从而导致循环:

    function __construct(EntityManager $em){
        // THIS WILL NOT WORK!
        $this->exampleRepo = $this->em->getRepository(Example::class);
    }
    

    这个问题似乎是一个时间问题。 EntityManager 加载存储库,每个存储库加载 Entitymanager,Entitymanager 依次加载存储库,...
    这会导致无限循环,从而导致解释器耗尽资源并返回 C 错误。


    注意:并非所有存储库都有这个问题,到目前为止我们还没有发现任何模式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-17
      • 2023-03-20
      • 1970-01-01
      • 2016-06-15
      • 2019-03-07
      • 2018-04-23
      相关资源
      最近更新 更多