Rotate file will loss logs and throw IOException
Closed this issue · 6 comments
I tested 400000 http requests with one log each, using fast-logger. Only 399377 logs save in the log files, and 24 error occured, which show
write: invalid argument (Bad file descriptor)
This message was raised by IOException
in GHC.IO.FD. writeRawBufferPtr
, but the cause of this error was renewLoggerSet
. This function call closeFD
directly after replace the fd
handler, while other threads may still using this handler to write logs.
This is not perfect but I will try to change System.Log.FastLogger.Logger.write
to take IORef FD
and read a fresh FD
just before writing.
@leptonyu Could you test https://github.com/kazu-yamamoto/logger/tree/ref-fd?
@kazu-yamamoto yes, I can.
@kazu-yamamoto I think it works.
I use this branch TestFastLogger
stack install demo
demo-web logging.file=.stack-work/1.log logging.max-size=1048576 logging.max-history=1000
## in another shell
hey -h2 -c 100 -n 1000000 http://localhost:8888/hello
cat .stack-work/1.log* | grep '200$' | wc -l
I got 1000000. Tried many times with no exception.
Nice. So, I will merge this onto master
and release a new version!
Done.