about summary refs log tree commit homepage
path: root/examples
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-01-25 18:07:52 -0800
committerEric Wong <normalperson@yhbt.net>2010-01-25 18:21:30 -0800
commit813cdd3cbc35a86ebf33aaf028937e70a15ddba0 (patch)
tree087639fb6e9057c5102de176be039baf73fe9d33 /examples
parentcb6d8c71abac83d75d2bc990bdbc84748a1309ea (diff)
downloadunicorn-813cdd3cbc35a86ebf33aaf028937e70a15ddba0.tar.gz
Thanks to Michael Guterl for informing us of the issues
and testing the monkey patch.
Diffstat (limited to 'examples')
-rw-r--r--examples/logger_mp_safe.rb25
1 files changed, 25 insertions, 0 deletions
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