Doctrine flush silently stops execution #6739

Closed
opened 2026-01-22 15:37:47 +01:00 by admin · 3 comments
Owner

Originally created by @jdiazgon55 on GitHub (May 28, 2021).

Hi!

Something pretty weird is happening to flush() in Symfony 4, php 7.4. When we persist and flush the entity, a new record is correctly added to the database.

However, the next line is not being executed. It seems flush() is breaking the normal code flow. This is what we have:

    public function new(Request $request, UserRepository $userRepository, ProyectoRepository $proyectoRepository, Empresa_UsuarioRepository $empresa_UsuarioRepository, EmpresaRepository $empresaRepository, ClienteRepository $clienteRepository, PermisosEmpleadoRepository $permisosEmpleadoRepository, PermisosEmpresaRepository $permisosEmpresaRepository)
    {
        $em = $this->getDoctrine()->getManager();
        $request = $this->transformJsonBody($request);
        $nombre = $request->get('nombre');
        $descripcion = $request->get('descripcion');
        $cliente_id = $request->get('cliente_id');
        $responsable_id = $request->get('responsable_id');
        $ubicacion = $request->get('ubicacion');
     
        $proyecto = new Proyecto();
        $proyecto->setIsActivo(true);
        $proyecto->setNombre($nombre);
        $proyecto->setCliente($cliente);
        $proyecto->setResponsable($responsable);
        $proyecto->setEmpresa($empresa);
        if (StaticUtilities::dataIsValid($descripcion))
        {
            $proyecto->setDescripcion($descripcion);
        }
        if (StaticUtilities::dataIsValid($ubicacion))
        {
            $proyecto->setUbicacion($ubicacion);
        }
        $em->persist($proyecto);
               
        $em->flush();
         // After this, nothing gets executed
        return $this->respondWithSuccess('Proyecto ' . $nombre . " creado con éxito");
    }

So, if we add an echo before and after flush(), we only see the first echo. We tried adding a try and catch but no exception is thrown.

If we remove the flush(), the next lines are executed correctly, so it must be there.

Is there any part of flush() that lacks exception handling?

Originally created by @jdiazgon55 on GitHub (May 28, 2021). Hi! Something pretty weird is happening to `flush()` in Symfony 4, php 7.4. When we persist and flush the entity, a new record is correctly added to the database. However, the next line is not being executed. It seems `flush()` is breaking the normal code flow. This is what we have: ```php public function new(Request $request, UserRepository $userRepository, ProyectoRepository $proyectoRepository, Empresa_UsuarioRepository $empresa_UsuarioRepository, EmpresaRepository $empresaRepository, ClienteRepository $clienteRepository, PermisosEmpleadoRepository $permisosEmpleadoRepository, PermisosEmpresaRepository $permisosEmpresaRepository) { $em = $this->getDoctrine()->getManager(); $request = $this->transformJsonBody($request); $nombre = $request->get('nombre'); $descripcion = $request->get('descripcion'); $cliente_id = $request->get('cliente_id'); $responsable_id = $request->get('responsable_id'); $ubicacion = $request->get('ubicacion'); $proyecto = new Proyecto(); $proyecto->setIsActivo(true); $proyecto->setNombre($nombre); $proyecto->setCliente($cliente); $proyecto->setResponsable($responsable); $proyecto->setEmpresa($empresa); if (StaticUtilities::dataIsValid($descripcion)) { $proyecto->setDescripcion($descripcion); } if (StaticUtilities::dataIsValid($ubicacion)) { $proyecto->setUbicacion($ubicacion); } $em->persist($proyecto); $em->flush(); // After this, nothing gets executed return $this->respondWithSuccess('Proyecto ' . $nombre . " creado con éxito"); } ``` So, if we add an `echo` before and after `flush()`, we only see the first `echo`. We tried adding a `try and catch` but no exception is thrown. If we remove the `flush()`, the next lines are executed correctly, so it must be there. Is there any part of `flush()` that lacks exception handling?
admin closed this issue 2026-01-22 15:37:48 +01:00
Author
Owner

@Fedik commented on GitHub (May 28, 2021):

We tried adding a try and catch but no exception is thrown.

Did you tried to catch an Exception or Throwable? If an Exception then try Throwable:

try {
  $em->flush();
} catch (\Throwable $t) {
 ... log error
}
@Fedik commented on GitHub (May 28, 2021): > We tried adding a try and catch but no exception is thrown. Did you tried to catch an `Exception` or `Throwable`? If an Exception then try Throwable: ``` try { $em->flush(); } catch (\Throwable $t) { ... log error } ```
Author
Owner

@beberlei commented on GitHub (May 31, 2021):

"silently stops" would point towards a segfault. Can you check your syslog or webserver error log for process crashes?

Otherwise you need to look at different error logs from your framework or error handlers, that is something you need to figure out as we have no means of helping oyu. Doctrine does not itself prevent exception handling so something must happen.

Maybe run with Xdebug tracing to find out where the code stops.

@beberlei commented on GitHub (May 31, 2021): "silently stops" would point towards a segfault. Can you check your syslog or webserver error log for process crashes? Otherwise you need to look at different error logs from your framework or error handlers, that is something you need to figure out as we have no means of helping oyu. Doctrine does not itself prevent exception handling so something must happen. Maybe run with Xdebug tracing to find out where the code stops.
Author
Owner

@beberlei commented on GitHub (Jun 5, 2021):

Closing due to missing feedback

@beberlei commented on GitHub (Jun 5, 2021): Closing due to missing feedback
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6739