Description
Symfony version(s) affected
5.4.11
Description
#46931 introduced a race condition between writing the profiler data and loading it as the browser now starts a XHR request to load the profiler data before the data is completely written.
The error produced when loading the incomplete profile dump is:
request.CRITICAL: Uncaught PHP Exception ErrorException: "Notice: unserialize(): Error at offset 3254883 of 3254908 bytes" at vendor/symfony/http-kernel/Profiler/FileProfilerStorage.php line 126 {"exception":"[object] (ErrorException(code: 0): Notice: unserialize(): Error at offset 3254883 of 3254908 bytes at vendor/symfony/http-kernel/Profiler/FileProfilerStorage.php:126)"
How to reproduce
Reproduction is difficult as it depends heavily on timing.
In general, the issue may occur for very large profile dumps stored on slow disks.
Possible Solution
This race condition can be fixed in two ways:
- Ensure the stored profile data on disk is always complete by storing the data into a temporary file and moving that file to the final location after everything is written in FileProfilerStorage.php#L177
- Use the @ operator on the unserialize operation in FileProfilerStorage.php#L124
I prefer solution 1 as solution 2 would hide other sources of corruption in the stored profile. A pull request for solution 1 will be provided shortly.
Additional Context
No response