From 1229a9991a4bf575bef5edb6180dac5b63fce5c5 Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Mon, 2 Jul 2012 23:39:30 -0700 Subject: [PATCH] Prevent NoMethodError/NameError from hanging the server. The fix is to work around this bug: http://bugs.ruby-lang.org/issues/4521 where Ruby will call to_s/inspect while printing exception messages, which can take a long time (minutes at full CPU) if the object is huge or has cyclic references, like Middleman::Application does. Defining #to_s short-circuits that. This fixes #370. --- middleman-core/lib/middleman-core/application.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/middleman-core/lib/middleman-core/application.rb b/middleman-core/lib/middleman-core/application.rb index f00b00dc..093edc13 100644 --- a/middleman-core/lib/middleman-core/application.rb +++ b/middleman-core/lib/middleman-core/application.rb @@ -217,6 +217,14 @@ module Middleman logging end + # Work around this bug: http://bugs.ruby-lang.org/issues/4521 + # where Ruby will call to_s/inspect while printing exception + # messages, which can take a long time (minutes at full CPU) + # if the object is huge or has cyclic references, like this. + def to_s + "the Middleman application context" + end + # Expand a path to include the index file if it's a directory # # @private