Patches: Browse | Submit New | Admin

[#6031] Bug in logger.rb rotation in multi-process environment

Date:
2006-10-05 09:08
Priority:
3
Submitted By:
Guy Rosen (guyrosen)
Assigned To:
Nobody (None)
Category:
Developer Tools/Libs
State:
Open
Summary:
Bug in logger.rb rotation in multi-process environment

Detailed description
Hi,

There is a bug in logger.rb's rotation that causes it to either misbehave or fail the application when running in a
multi-process environment - specifically Rails.

I have Ruby on Rails under FastCGI, with multiple dispatch.fcgi processes running. My logger is configured for daily
rotation. The problematic scenario is this:
 - Come midnight, the _first_ Rails process that happens to get a request renames the log file (production.log =>
production.log.yyyymmdd)
 - Subsequently, the remaining Rails processes attempt to rename the file as well, but fail completely because
production.log.yyyymmdd already exists. Logger raises an exception, and users receive "500 Internal Server
Error".
 - Until all Rails processes are restarted, only the first one will work and all the rest will continue to fail
violently.

I'm attaching a patch for logger.rb that fixes shift_log_period so that it doesn't fail violently if log.yyyymmdd already
exists, but rather just reopens the logfile and keeps on working.

Note there is probably also a bug when rotating by size (shift_log_age) in the same environment (haven't tested or fixed
it, but reading the code seems to indicate it will happen). Although nothing will fail violently, each Rails process,
ignorant of its peers, will rotate the logs and the end result will be multiple rotations!

 - Guy.

Add A Comment: Notepad

Please login


Followup

No Followups Have Been Posted

Attached Files:

Name Description Download
patch Patch for lib/logger.rb Download

Changes:

Field Old Value Date By
assigned_tozenspider2009-02-18 03:29zenspider
assigned_tonone2007-06-13 06:27zenspider
category_idMisc / Other Standard Library2007-05-30 04:18zenspider
category_idNone2007-05-30 03:50zenspider
File Added841: patch2006-10-05 09:08guyrosen