4266: Tweak long-line handling.
authorTom Clegg <tom@curoverse.com>
Tue, 21 Oct 2014 17:46:00 +0000 (13:46 -0400)
committerTom Clegg <tom@curoverse.com>
Tue, 21 Oct 2014 17:46:00 +0000 (13:46 -0400)
services/api/script/crunch-dispatch.rb

index bbb2be9a33a399cbc9413c2f8e5868950e1d8d91..94311edea43689a753daa1a11ce5b016567983d0 100755 (executable)
@@ -450,14 +450,20 @@ class Dispatcher
         bufend = ''
         streambuf.lines("\n").each do |line|
           if not line.end_with? "\n"
-            if line.size > 2**20
+            if line.size > Rails.configuration.crunch_log_throttle_bytes
               # Without a limit here, we'll use 2x an arbitrary amount
               # of memory, and waste a lot of time copying strings
               # around, all without providing any feedback to anyone
               # about what's going on _or_ hitting any of our throttle
-              # limits. Better to introduce a spurious line break once
-              # in a while:
-              line << "[...]\n"
+              # limits.
+              #
+              # Here we leave "line" alone, knowing it will never be
+              # sent anywhere: rate_limit() will reach
+              # crunch_log_throttle_bytes immediately. However, we'll
+              # leave [...] in bufend: if the trailing end of the long
+              # line does end up getting sent anywhere, it will have
+              # some indication that it incomplete.
+              bufend = "[...]"
             else
               # If line length is sane, we'll wait for the rest of the
               # line to appear in the next read_pipes() call.