> Once we await that callback to resolve, then the buffered data from before that point is known to be flushed.
This is not true IME. Just more likely.
See my comment here: https://news.ycombinator.com/item?id=41829905
> If I wait for finish, a background “thread” can extend the process lifetime by continuing to log.
Can you not address this by calling .end() on the stream?
https://nodejs.org/api/stream.html#writableendchunk-encoding...
> Our rule: if you want the process to wait for your async work to complete, then `await` it.
In general I very much agree. In this specific case, though, the awaits are just buying you a bit more time to race the buffer which is why they appear to help. The "flush" will not wait for completion before exiting the process.
Maybe also worth keeping in mind that even if this would be working, stuff like this has historically changed breakingly a few times between major Node releases. If you're relying on unspecified behavior you're obviously in darker waters.