https://github.com/egladman/herodotus/blob/master/server.js#...
How can a developer be that stupid?
file.write is atomic (guaranteed to "work") for PIPE_BUF (posix) octects ~ 16ko at most.
JSON is guaranteed to be unparsable if the file is truncated of the last chars (it is not very resilient).
Hence the write may corrupt your WHOLE log if a non recuperable failure happens or the code is interrupted.
The code DOES not use fixed size allocation ... thus is can crash randomly because of SEGFAULT in the middle of the writing. The history will take cumulative size in memory.
This coding attitude highers the probability of this failure to happen BY DESIGN.
Is it that complex to FIRST write the file, and THEN atomically rename the new file to the old file at worst (resulting only in losing the current session, but not the whole history).
If your log are that precious, why would you not take extra care about protecting them?
This code makes me want to puke.
On the other hand, it is representative of the reason why I am disenchanted by modern coding standards.