Log reads can fail with Errno::EACCES during LogDevice rotation on Windows
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 48/100
Línea de trabajo
Start with LogDevice#lock_shift_log and the Windows locking change in commit 7b6146f; the reproduction in the issue shows how a separate reader fails during rotation. Compare the locking behavior with create_logfile and the referenced draft PR fluent/fluentd#5690. Done means choosing and implementing a locking approach that allows reads during rotation while keeping rotators mutually exclusive, then verifying the reproduction on Windows.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Since logger 1.6.3, a read through a separate handle can fail with Errno::EACCES during log rotation on Windows. Commit 7b6146f enabled flock(File::LOCK_EX) in LogDevice#lock_shift_log on Windows. Ruby implements flock there with LockFileEx. The lock is mandatory and covers the whole file.
For example, when Fluentd tails its own log, a read during rotation sometimes fails with Permission denied @ io_getpartial. Fluentd then loses the lines it has not yet read.
Reproduction
The hook makes the read happen at the same point in rotation on every run. In the affected versions, lock_shift_log already holds the lock at that point. A polling reader can hit the same window by chance.
require "logger"
require "tmpdir"
Dir.mktmpdir do |dir|
path = File.join(dir, "app.log")
logger = Logger.new(path, 3, 1024)
logger.info("x" * 1024)
# Open a separate handle to simulate a program that tails the log.
reader = File.open(path, File::RDONLY | File::BINARY | File::SHARE_DELETE)
# Read at the start of shift_log_age, then let rotation continue.
result = nil
hook = Module.new do
private
define_method(:shift_log_age) do
begin
result = "read #{reader.read.bytesize} bytes"
rescue Errno::EACCES => e
result = "#{e.class}: #{e.message}"
end
super()
end
end
logger.instance_variable_get(:@logdev).singleton_class.prepend(hook)
logger.info("rotate")
puts "logger #{Logger::VERSION}: #{result}"
reader.close
logger.close
end
Output on Windows 10 (ruby 3.4.13 x64-mingw-ucrt):
logger 1.6.2: read 1143 bytes
logger 1.6.3: Errno::EACCES: Permission denied @ io_fread - .../app.log
logger 1.7.0: Errno::EACCES: Permission denied @ io_fread - .../app.log
Possible fix
One option on Windows is to use LockFileEx to lock a single byte far beyond EOF. Windows allows this, and reads of the log data do not overlap that byte. Rotators that lock the same byte would still wait for each other. A whole-file flock from logger 1.6.3 to 1.7.0 also covers that byte, so mixed versions would still exclude each other. Raymond Chen describes this technique in You can use a file as a synchronization object, too.
The draft PR fluent/fluentd#5690 tries this approach. It overrides lock_shift_log and calls LockFileEx through Fiddle. If you prefer not to call a Win32 API from logger, could the locking step be made overridable?
Related behavior
create_logfile also holds flock(File::LOCK_EX) while writing a new log header. It holds the lock for much less time. Older versions also lock the file here.
#165 is another Windows problem around lock_shift_log after logger 1.6.2.
- Lenguaje dominante
- Ruby
- Estrellas
- 161
- Forks
- 76
- Merge medio
- 2 d 5 h
- PR fusionados (30 d)
- 3
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de ruby/logger
-
Programs using Logger sometimes resist SIGTERM / SIGINTPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
Later writes fail with "closed stream" when renaming the log fails during rotation on WindowsAbierto
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
-
Dificultad 3/5 1-2 días Aptitud para principiantes 52/100
-
`datetime_format=` does not apply to custom formattersPosiblemente ocupada @Rubyist007 la tomó hace 229 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
Todos los issues de ruby/logger
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
open-feature/ruby-sdk-contrib#340 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
zold-io/wts.zold.io#651 ·
Los mantenedores suelen responder en 1 día
-
good first issue help wanted
Dificultad 2/5 1-3 horas Aptitud para principiantes 87/100
erkamyaman/rust-anything#788 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 74/100
TheOdinProject/curriculum#31579 ·
Los mantenedores suelen responder en 1 día