Search code examples
node.jstail

text alignment bug when using "tail -F foo.log" which is being written to from multiple sources


I am seeing this weird "bug" whereby when I tail a file using tail -F foo.log, some of the content is actually indented the wrong way, so the first 20 or so characters are getting truncated. Anyone seen something like this before? Really weird and not sure why it's happening. Some of the text is aligned correctly, and some isn't.

The file is being written to from multiple Node.js processes, but I can pretty much guarantee that none of the processes are truncated the first ~20 characters before writing to the file!

My only hypothesis is because multiple processes are writing to the same file and some of the processes are using the 'w' flag and others are using the 'a' flag, this might cause some corruption? The corruption is very consistent/deterministic each time.


Solution

  • Looks like this was due to writing to the same file with the same process using 'a' and 'w' flags - Write in a text file without overwriting in fs node js