I think there is probably a super-rare issue with the Moodle filesystem when using NFS, but am unable to satisfactorily reproduce it - that is, I can reproduce it every time with a specific piece of (custom, local) code but can't reproduce it with a simplified test. So I'm giving up on the issue and doing a workaround but thought I would post here in case anyone else has encountered it.
The issue is that an AJAX script of ours sometimes gets the following errors:
Warning: filesize(): stat failed for .../moodledata/filedir/93/bf/93bf66a8d4ca85ce4ab4d357169e8a24871415a7 in .../lib/filestorage/file_storage.php on line 1763
Warning: sha1_file(.../moodledata/filedir/93/bf/93bf66a8d4ca85ce4ab4d357169e8a24871415a7): failed to open stream: No such file or directory in .../lib/filestorage/file_storage.php on line 1766
Here are the lines of code:
if (file_exists($hashfile)) {
if (filesize($hashfile) === $filesize) { // 1763
return array($contenthash, $filesize, false);
}
if (sha1_file($hashfile) === $contenthash) { // 1766
Looking at this, you can see that file_exists is returning true, but then the following errors indicate the file does not actually exist.
The error only occurs on a system with two webservers using NFS for a shared moodledata. There is no need to make simultaneous requests to trigger the error - you can trigger it by making one request, waiting until it completes, then making another a second later. (The error doesn't always happen, but it reliably happens after <10 iterations, usually only three or four.)
So the error is consistent with the supposition (I found this information online) that NFS by default caches information about file existence for 3 seconds, but does not cache if you actually open the file, so therefore the file_exists can return true but actually opening it for sha_file will fail, if the file was deleted by a different server.
A certain way of using our script [if you change something then change it back] causes it to modify the contents of a file between two values, i.e. the file contents is A, then using the script it gets set to B, then using it again gets set back to the previous contents A. This will have the effect of repeatedly deleting a file (A) and then creating it again within a short time period.
All quite straightforward so far, right? ;) I was going to file it in the Moodle Tracker and submit a patch...
...But the story now comes to a crashing halt right here, because basically I've been trying to make a short test script that does the exact same thing as my real AJAX script, and calling it in the same way (using a javascript test harness and an iframe) on the same 2-server system where the real one fails, but I cannot for the life of me get that one to fail.
So I think my speculation about the cause of these errors is probably wrong and something else is involved. I've run out of time, but if anyone else has any suggestions, do let me know.
--sam