custodia
custodia copied to clipboard
auditlog: logging.FileHander() is not fork-safe
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.
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)
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