Skip to content

Commit

Permalink
minor #50947 [HttpKernel] Skip corrupted CSV data in FileProfilerStor…
Browse files Browse the repository at this point in the history
…age (radar3301)

This PR was merged into the 6.3 branch.

Discussion
----------

[HttpKernel] Skip corrupted CSV data in FileProfilerStorage

| Q             | A
| ------------- | ---
| Branch?       | 6.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Partially fixes #50942, improves/fixes on PR #50913, partially fixes #50816
| License       | MIT

Technically, part of this fix could go all the way back to 2.1, but since we're not sure why/how exactly the index.csv file is being corrupted in the first place, this PR should just serve as a stop-gap measure until the root cause can be identified.

A corrupted index.csv file is especially noticeable since 6.3, when the "Remove Expired Profiles" feature was added by #47352 .

RE: improves/fixes on PR #50913:
Warnings are (usually?) only escalated to errors in debug mode, so having a try/catch is a bit more overhead than I think is actually needed, and I believe just checking that the line read from the csv is not corrupted is the better/faster option. Granted, the profiler should really only be active in debug/non-production modes anyway, but "should" and reality usually don't align...

`@alamirault` `@MatTheCat` `@benjaminfunk` `@Pelagoss` `@derrabus`

Commits
-------

b4e942d Update FileProfilerStorage.php
  • Loading branch information
nicolas-grekas committed Jul 13, 2023
2 parents 09f5778 + b4e942d commit 201ad71
Showing 1 changed file with 9 additions and 1 deletion.
Expand Up @@ -315,7 +315,15 @@ private function removeExpiredProfiles(): void
}

while ($line = fgets($handle)) {
[$csvToken, , , , $csvTime] = str_getcsv($line);
$values = str_getcsv($line);

if (7 !== \count($values)) {
// skip invalid lines
$offset += \strlen($line);
continue;
}

[$csvToken, , , , $csvTime] = $values;

if ($csvTime >= $minimalProfileTimestamp) {
break;
Expand Down

0 comments on commit 201ad71

Please sign in to comment.