From: Eric Wong <normalperson@yhbt.net>
To: mongrel-unicorn@rubyforge.org
Subject: [PATCH] KNOWN_ISSUES: background threads + Logger monkey patch
Date: Mon, 25 Jan 2010 18:35:53 -0800 [thread overview]
Message-ID: <20100126023553.GA7011@dcvr.yhbt.net> (raw)
Thanks to Michael Guterl for informing us of the issues
and testing the monkey patch.
---
Pushed out to the website and unicorn.git
KNOWN_ISSUES | 8 ++++++++
examples/logger_mp_safe.rb | 25 +++++++++++++++++++++++++
2 files changed, 33 insertions(+), 0 deletions(-)
create mode 100644 examples/logger_mp_safe.rb
diff --git a/KNOWN_ISSUES b/KNOWN_ISSUES
index 83b3584..e83e34e 100644
--- a/KNOWN_ISSUES
+++ b/KNOWN_ISSUES
@@ -3,6 +3,14 @@
Occasionally odd {issues}[link:ISSUES.html] arise without a transparent or
acceptable solution. Those issues are documented here.
+* When using "preload_app true", with apps using background threads
+ need to restart them in the after_fork hook because threads are never
+ shared with child processes. Additionally, any synchronization
+ primitives (Mutexes, Monitors, ConditionVariables) should be
+ reinitialized in case they are held during fork time to avoid
+ deadlocks. The core Ruby Logger class needlessly uses a MonitorMutex
+ which can be disabled with a {monkey patch}[link:examples/logger_mp_safe.rb]
+
* Rails 2.3.2 bundles its own version of Rack. This may cause subtle
bugs when simultaneously loaded with the system-wide Rack Rubygem
which Unicorn depends on. Upgrading to Rails 2.3.4 (or later) is
diff --git a/examples/logger_mp_safe.rb b/examples/logger_mp_safe.rb
new file mode 100644
index 0000000..05ad3fa
--- /dev/null
+++ b/examples/logger_mp_safe.rb
@@ -0,0 +1,25 @@
+# Multi-Processing-safe monkey patch for Logger
+#
+# This monkey patch fixes the case where "preload_app true" is used and
+# the application spawns a background thread upon being loaded.
+#
+# This removes all lock from the Logger code and solely relies on the
+# underlying filesystem to handle write(2) system calls atomically when
+# O_APPEND is used. This is safe in the presence of both multiple
+# threads (native or green) and multiple processes when writing to
+# a filesystem with POSIX O_APPEND semantics.
+#
+# It should be noted that the original locking on Logger could _never_ be
+# considered reliable on non-POSIX filesystems with multiple processes,
+# either, so nothing is lost in that case.
+
+require 'logger'
+class Logger::LogDevice
+ def write(message)
+ @dev.syswrite(message)
+ end
+
+ def close
+ @dev.close
+ end
+end
--
Eric Wong
_______________________________________________
Unicorn mailing list - mongrel-unicorn@rubyforge.org
http://rubyforge.org/mailman/listinfo/mongrel-unicorn
Do not quote signatures (like this one) or top post when replying
reply other threads:[~2010-01-26 2:36 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://yhbt.net/unicorn/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100126023553.GA7011@dcvr.yhbt.net \
--to=normalperson@yhbt.net \
--cc=mongrel-unicorn@rubyforge.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhbt.net/unicorn.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).