In a web page, I trigger many ajax calls. During some them, one variable of the session is lost. However, the user is not logged out, it is only the session variable that seems to be erased.
It’s happening like once in 250 times and I can’t reproduce it in development mode.
In one of them, I have an ajax request nested in the other, it is always the second that triggers an error (when it occurs) like such :
$.ajax({
type: "GET",
url: "{{ path('route_1') }}",
async : true,
success: function(mydata)
{
$('#list').html(mydata['rend']).show();
$.ajax({
type: "GET",
url: "{{ path('route_2') }}", /* This one */
success: function(mydata)
{
$('#options').html(mydata['rend']).show();
}
}
});
}
});
Here is an example of the debug file in prod when it throws the error
(the date is ‘–‘ because of session[‘var’]->date(‘d’).’-‘.session[‘var’]->date(‘m’).’-‘.session[‘var’]->date(‘Y’)) :
[2024-05-30 15:17:44] security.DEBUG: Stored the security token in the session. {"key":"_security_main"} []
[2024-05-30 15:33:58] request.INFO: Matched route "my_request". {"route":"my_request","route_parameters":{"_route":"my_request","_controller":"RouteToController\Controller::myFonction","_locale":"fr"},"request_uri":"https://siteweb.com/url","method":"GET"} []
[2024-05-30 15:33:58] security.DEBUG: Read existing security token from the session. {"key":"_security_main","token_class":"Symfony\Component\Security\Core\Authentication\Token\RememberMeToken"} []
[2024-05-30 15:33:59] security.DEBUG: User was reloaded from a user provider. {"provider":"Symfony\Bridge\Doctrine\Security\User\EntityUserProvider","username":"user"} []
[2024-05-30 15:33:59] security.DEBUG: Checking for guard authentication credentials. {"firewall_key":"main","authenticators":1} []
[2024-05-30 15:33:59] security.DEBUG: Checking support on guard authenticator. {"firewall_key":"main","authenticator":"App\Security\LoginFormAuthentificatorAuthenticator"} []
[2024-05-30 15:33:59] security.DEBUG: Guard authenticator does not support the request. {"firewall_key":"main","authenticator":"App\Security\LoginFormAuthentificatorAuthenticator"} []
[2024-05-30 15:33:59] request.CRITICAL: Uncaught PHP Exception TwigErrorRuntimeError: "An exception has been thrown during the rendering of a template ("DateTime::__construct(): Failed to parse time string (--) at position 0 (-): Unexpected character")." at file.html.twig line 12 {"exception":"[object] (Twig\Error\RuntimeError(code: 0): An exception has been thrown during the rendering of a template ("DateTime::__construct(): Failed to parse time string (--) at position 0 (-): Unexpected character"). at file.html.twig:12, Exception(code: 0): DateTime::__construct(): Failed to parse time string (--) at position 0 (-): Unexpected character at /path/vendor/twig/twig/src/Extension/CoreExtension.php:546)"} []
[2024-05-30 15:33:59] security.DEBUG: Stored the security token in the session. {"key":"_security_main"} []
I first installed Redis, thinking it was a concurrent request problem and that it would solve it but it keeps happening. I tried to set async:false on some of the problematic ajax calls but didn’t do the trick either.
Finally, I tried to set 1s timeout but, guess what, didn’t work either.
This bug is very difficult to locate and the random fact really doesn’t help. If this is not a concurrent request problem then I can’t seem to find any viable solution…
Any help would be greatly appreciated, thank you !