Warnings in file cache
Description
As per https://www.simplemachines.org/community/index.php?topic=581722.0 the fopen call in the file cache can warning-out with file not found.
Steps to reproduce
- Set up a race condition across multiple requests!
Environment (complete as necessary)
- Version/Git revision: 2.1.1
- Database Type: n/a
- Database Version: n/a
- PHP Version: probably n/a
Additional information/references
As per topic, the only thing you can do is @ out the fopen/fread/fclose calls because the functions can fail for reasons you can’t account for.
PHP messed around with the @ operator in recent versions. A fix should use try/catch instead to not deal with PHP's weirdness.
The @ operators still work for file ops though.
Good to know. I've been using try/catch because I can handle it at least safely
The problem is that not all file ops emit catchable warnings in all the versions SMF still claims to support.
PHP again you anger me. I don't see why it can't be catchable..
Actually, I made the assumption that it was a catchable in PHP 8 but this little proof of concept suggested otherwise when I ran it on 3v4l:
try {
fopen('/tmp/doesnotexist', 'r');
} catch (\Throwable $e) {
echo 'Caught!';
} catch (\Exception $e) {
echo 'Caught!';
}
Every version of PHP from 5.3 through 8.1 reacted the same way - issuing the E_WARNING. That's the core repro case from the user who originally reported it. Now we could handle this in the error logger but honestly, it's already too late for that because this is something we know can legitimately fail and it not be something we can do anything about, and we shouldn't really log it in that case.