custodia icon indicating copy to clipboard operation
custodia copied to clipboard

auditlog: logging.FileHander() is not fork-safe

Open tiran opened this issue 8 years ago • 2 comments

Custodia uses logging.FileHandler to log audit events to a log file. The file handler is thread-safe but it is not multi-process safe. It does not synchronize writes for multiple writers or inherited FDs in forked child processes.

I don't have a quick solution at hand.

tiran avatar Mar 02 '17 13:03 tiran

One thing we could do is to have the logging go to the parent process over a FD instead, and have the parent process collect it and commit it to the log file all at once when the child dies, or on a message based boundary (TBD). (This will make log rotation easier if we want to do it from within custodia)

simo5 avatar Mar 02 '17 14:03 simo5

Either in the main process of we fork off a logging process.

Python has a watching file handler that handles flush, close and reopen: https://github.com/python/cpython/blob/3.6/Lib/logging/handlers.py#L446

tiran avatar Mar 02 '17 14:03 tiran