Closed Roguelazer closed 3 months ago
I ran into the same error when I tried using log macros over TCP. Messages were never sent. Changing to UDP solved the problem. If TCP is going to be a supported protocol, every message needs to be flushed or valuable data can be dropped. This issue is over a year old and needs to be addressed.
I concur and can reproduce this issue - UDP is working fine but not TCP.
TCP is hardly useable without this fix.
@Geal The PR resolving this issue has been sitting open for a couple years. Can it get some direction on a path forward if it's not acceptable to merge?
Since #30, TcpStream and UdpStream use a BufWriter, which gets flushed in the
flush()
method in theLog
trait impl. However, this method never actually is called in the normal use of thelog
crate (e.g.,log!()
and friends never call it). This means a program which logs less than one BufWriter worth of data (8KB) will never actually emit any of those messages, and the last few messages logged are always lost.This can be easily demonstrated with the following program, which (if run on a system where
/dev/log
is a stream-mode domain socket) will never log anything:Explicitly calling
flush
does, of course, work:The following patch fixes this, at the cost of doing rather a lot more system calls under load:
Normally I run syslog in datagram mode, so I've never run into this before.