I need to do something basic, I have two entities: User and Action. Each User has X tokens assigned by the Admin and then he can perform Y actions based on the amount of tokens. So lets say one User only has enough tokens to perform one Action, I identified that if I perform multiple simultaneously requests at the same exact time (like 5 or more requests at the same time). Instead of just one Action, the User executes two or more Actions (and only in the explained scenario, in the rest everything works fine)

The related code to my explanation:

```
public function useractions(Requests $request){
        $user = $this->getUser();
        $post = Request::createFromGlobals();
        if($post->request->has('new_action') && $this->isCsrfTokenValid("mycsrf", $post->request->get('csrf_token'))) {
            $entityManager = $this->getDoctrine()->getManager();
            $tokens = $user->getTokens();

            if($tokens<1){
                $error = "Not enough tokens";
            }
            if(empty($error)){
                $user->setTokens($tokens-1);
                $entityManager->flush();
                $action = new Action();
                $action->setUser($user);
                $entityManager->persist($transaction);
                $entityManager->flush();
             }
         }
}

```

And I am using mariadb 10.5.12 with InnoDB as the engine

Obviously I am making a big mistake in my code or missing something in the Symfony or Doctrine configuration. Someone could tell me the mistake? Thanks