Fix panic on slow log consumer.

Fixes #8832

All stdio streams need to finish writing before the
connection can be closed.

Signed-off-by: Tõnis Tiigi <tonistiigi@gmail.com> (github: tonistiigi)

ping @LK4D4 @jfrazelle