Skip to content

Entity manager is closed error after upgrading to Symfony 7.3 #61005

Open
@fvozar

Description

@fvozar

Symfony version(s) affected

7.3.0, 7.3.1

Description

I'm using frankenphp in worker mode as runtime, and after upgrading from Symfony 7.2 to Symfony 7.3, the entity manager is not properly "refreshed" between requests in case of a database exception.

When a database exception occurs for the first time, any other update/insert fails with The EntityManager is closed. error, and the application can't handle other calls successfully after that.

The same code with Symfony 7.2 behaves normally.

How to reproduce

I've prepared a working demo here: https://github.com/fvozar/frankenphp-symfony-error. It's based on official php-runtime/frankenphp-symfony setup.

Let's assume a simple entity with a unique field:

#[ORM\Entity(repositoryClass: FooRepository::class)]
#[ApiResource]
class Foo
{
    #[ORM\Id]
    #[ORM\GeneratedValue]
    #[ORM\Column]
    private ?int $id = null;

    #[ORM\Column(length: 255, unique: true)]
    private string $title = '';
}

The following consecutive calls demonstrate the error:

POST /api/foos 
{ "title": "foo" }

Result is 201 - expected

POST /api/foos 
{ "title": "foo" }  <-- same payload, should fail on unique constraint

Result is 500 - unique constraint failure on Doctrine; also expected; I omitted handling exceptions for simplicity here.

POST /api/foos 
{ "title": "bar" }

Result is 500 - Entity manager is closed; however, I would expect 201 since this payload does not violate the unique constraint anymore.

Possible Solution

No response

Additional Context

I've created an issue in the frankenphp repo, but I got a recommendation to create the issue here instead. Link to original issue: php/frankenphp#1707

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions