-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
RotatingFileHandler fails when logs are stored in a non-posix file system docker-mounted in Linux-OS #120647
Comments
This is strange. There were no changes in this part of code since 3.11 (and the last change was making so that only regular files are now rotated, not symlinks, devices or named pipes). The EBADF error should only be raised if the file descriptor was closed, unless there is a nonstandard behavior for your “double mounting” combination. This can only happen when the RotatingFileHandler is concurrently used in different threads. But every code that uses cc @vsajip |
I took my time to look at the ohter projects of us. I found out that we never actually deployed 3.11 to production. We have one project running on 3.9 and the rest are rocking 3.10.
@serhiy-storchaka do you have a possible explanation for this? |
Do you use RotatingFileHandler or TimedRotatingFileHandler? The former should not rely on time. Can it be an external issue, caused by scheduled maintenance of the mounted file system? How much rollovers occurred in a week? BTW, do your program use forking? If the handler is created in the parent process which was later forked, the file descriptors may be closed in the child process. Although nothing was changed in 3.10 or 3.11. Significant changes were in 3.4. Try to unmount the file system with logs and then mount it back. Does it cause the same issue? |
After further investigation, I have to give up on this side. I was not really able to narrow down the issue and identify its cause. Some additional info that I gathered:
|
Bug report
Bug description:
Issue description
The
RotatingFileHandler
fails to execute the methodself.shouldRollover()
because of anOSError: [Errno 9] Bad file descriptor
.Background info: The issue appears in an application running in Docker on Debian. I use Windows Server 2016 as my main file server, so I usually want all my logs stored over there.
I really do not want to provide any misleading information but to me, it looks like the issue started appearing with python 3.12.
I've been using the python logging module for years now within a lot of different projects, all running in docker and always storing the log files over to my Windows file server through this “double mounting” technique (more about this down below).
I started seeing the issues when I first deployed an app with python 3.12. This was a new project, which never ran under previous python versions. However, I have a couple of other projects which shares the same code and the same logging technique but still run previous python versions (nothing ancient, >=3.9). This issue never came up there.
My guess is that python threats the directory as posix-complient as it detects a Linux-OS, although this is not the case as the directory lives on a NTFS file system on Windows. May this be the case?
Strange fact 😵: My app runs 24/7. It runs the whole week no problem, writes a lot of log entries like a charme. But when I come back after the weekend, I find it “stuck” on this error. As if the shouldRollover() method somehow gets called at specific interval or day-of-week? I observed this behavior 3 weeks in a row. Could it be?
To reproduce:
Host OS: Debian 12 Bookworm
Host Kernel: Linux debjm02 6.1.0-21-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.90-1 (2024-05-03) x86_64 GNU/Linux
Docker version: 26.1.1, build 4cf5afa
Docker image: python:3.12-slim-bookworm
Mounting "technique":
via cifs and /etc/fstab
under/mnt/servers/
/mnt/servers/myapp/logs/
is then mounted into container under/logs/
(via docker volumes)Creation of Logger with rotating log file
Error and Stacktrace
CPython versions tested on:
3.12
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: