Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log rotation does not work if the log file has multiple owner processes #3131

Open
lesnikowka opened this issue Jul 9, 2024 · 0 comments
Open

Comments

@lesnikowka
Copy link

Linked issue(closed): #2347

The rotate_ method when rotating logs uses std::rename, which cannot rename a file if it has multiple owners. We try to rename the files 2 times, if we fail, then we overwrite the log file and lose the old information. I suggest that 2 solutions:

  1. (OK) Disable inheritance of the log file descriptor. Sometimes you need to allow inheritance of descriptors in the CreateProcess function, in which case inheritance of the log file descriptor ruins everything, rotation does not work.
  2. (NOT WELL) If for some reason we cannot disable file descriptor inheritance (I didn’t look at this point in the code), then we can do this: if renaming fails, create a new file and copy the data into it, overwriting the current file. This may take time, but we already spend 100ms when rename fails. One could set this as an option when using the logger.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant