Append sometimes overwrites file with garbage
Original Reporter info from Mantis: uhthome
-
Reporter name: Ulrich Thome
Original Reporter info from Mantis: uhthome
- Reporter name: Ulrich Thome
Description:
To tell the story I have to start in 2010. I wrote a program to log data from my solar inverter and write it to a text file. The program was complied using fpc 2.4.0 on a windows 2000 computer. The resulting exe file was run on a diferent machine. It was scheduled by the windows scheduler to start once a day and add a line to a text file. It ran flawlessly for 4 years on WHS 2001 (i.e. windows Server 2003) and subsequently for 1 year on a WHS 2011 (i.e. Server 2008 R2).
At that time, I recompiled the program using fpc 2.6.4 on a win7-64 AMD Phenom II machine because I wanted to change the drive letter of the path where the log file is supposed to be written to. Surprisingly, the exe became 100.000 bytes longer. (419.000 bytes instead of 319.000 bytes). When using this program, for sevaral weeks, the log file became repeatedly overwritten by garbage, leding to data loss. It worked well for a while and suddenly there was only garbage left, with some correct readings at the end of the file, and the file maintained the correct length. Another log file simultaneously written to a network drive was not harmed. As a hot fix, I went back to the old exe file and changed the drive letter using a hex editor to avoid recompiling. With the old exe, the issue was gone.
More recently, I wrote another similar program to log data from an electric meter. I compiled it with fpc 2.6.4 and deployed it. After 1 week of normal functioning. I found again the respective log file full of garbage. An example is attached.
Now I got frustrated and uninstalled fpc 2.6.4. Instead, I went back to fpc 2.4.0, installed it on the Windows 7 machine used for development, recompiled both programs and deployed them on the home server. The problem has not recurred yet, hopefully it is gone. Furthermore, the fpc 2.4.0 compiled programs are much smaller than the ones compiled with fpc 2.6.4.
Steps to reproduce:
Running the program every day by the windows scheduler occasionally leads to a corrupted log file on the internal drive pool (v:). The programs are set to write the file twice, the other one, going to the network drive (y:), remains unharmed. It is unclear when the file corruption happens and what causes it. It is also unclear why it does not happen every day. I suspect it is related to the code generated by fpc 2.6.4 rather than 2.4.0, and maybe interference with the special environment the programs are deployed in (see below).
Additional information:
The computer running the compiled programs is an AMD N54L with ECC RAM, running WHS2011 alias Windows Server 2008 R2. Furthermore, transparent raid by Flexraid is installed, and the log files are being written on the pooled drive created by Flexraid.
By the way, If you think my programming is funny, don't worry. My real profession is medicine. I am programming only small things to automate things in my home and make my life a bit easier.
Mantis conversion info:
- Mantis ID: 27670
- OS: Windows Server
- OS Build: 2008 R2
- Platform: x86/x64
- Version: 2.6.4
- Monitored by: » crossbuilder (Burkhard Carstens), » uhthome (Ulrich Thome)