We have a situation where files are uploaded to a folder by FTP and then served by nginx. We've found that if the GET request immediately follows the modification of the file nginx returns files with 0 bytes.
In trying to debug this problem I wrote 2 python scripts to see if I could reproduce the error in a simple way.
The first one writes to a file
while True:
with open('testfile' , 'w') as f:
f.write("test")
And the second one reads
while True:
with open('testfile' , 'r') as cf:
print(cf.read())
when running these files in 2 separate processes the output of the reader is either "test" or "" indicating that sometimes the file seems empty to the reader. This does not seem to be related to the python implementation as I can reproduce the effect with bash like this:
(writer.sh)
while true; do
echo test > testfile
done
(reader.sh)
while true; do
cat testfile
printf "\n"
done
The file system is ext4 and the OS is Ubuntu 16.04.
So:
Why does the reader sometimes see an empty file (around 50% of the time)?
Why do we never see a partial write ("te", "tes" etc)?
Thanks in advance for you help.