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.
> How can a developer be that stupid? [...] This code makes me want to puke.
This comment breaks the HN guidelines so badly that we could put it on a poster of how never to behave here. It doesn't matter how right you are if you express it this abusively.
Since you've done this more than once before, I've banned your account. If you don't want it to be banned, you're welcome to email hn@ycombinator.com and give us reason to believe that your comments will be civil in the future.
Not Julie. It is a pun in french. Julie is like calling me Hanni when my real name is more like Hanniballs. And I still have my balls. So keep it julie1.
But I guess you may lack of context to get it right, as for the rest of your comment. ;)
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.