Skip to content

Commit 90f4e13

Browse files
committed
Truncate error backtrace when saving failed executions
Otherwise it can get really big for SystemStackError errors, and not fit in the DB text column. Assuming an average of 150 characters per backtrace line, limting to 400 would be around 60K characters plus the error name and error message, that are usually small, and the JSON attributes and other JSON serialization characters. This is the first approach to this. I'll change this to more sophisticated truncation that checks the column size and calculates how much it needs to truncate instead of using a fixed number.
1 parent fa0a5cb commit 90f4e13

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

app/models/solid_queue/failed_execution.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ def retry
3333
end
3434

3535
private
36+
BACKTRACE_LINES_LIMIT = 400
37+
3638
def expand_error_details_from_exception
3739
if exception
38-
self.error = { exception_class: exception.class.name, message: exception.message, backtrace: exception.backtrace }
40+
self.error = { exception_class: exception.class.name, message: exception.message, backtrace: exception.backtrace.first(BACKTRACE_LINES_LIMIT) }
3941
end
4042
end
4143
end
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class InfiniteRecursionJob < ApplicationJob
2+
queue_as :background
3+
4+
def perform
5+
start
6+
end
7+
8+
private
9+
def start
10+
continue
11+
end
12+
13+
def continue
14+
start_again
15+
end
16+
17+
def start_again
18+
start
19+
end
20+
end

test/models/solid_queue/failed_execution_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ class SolidQueue::FailedExecutionTest < ActiveSupport::TestCase
1414
assert SolidQueue::Job.last.failed?
1515
end
1616

17+
test "run job that fails with a SystemStackError (stack level too deep)" do
18+
InfiniteRecursionJob.perform_later
19+
@worker.start
20+
21+
assert_equal 1, SolidQueue::FailedExecution.count
22+
assert SolidQueue::Job.last.failed?
23+
end
24+
1725
test "retry failed job" do
1826
RaisingJob.perform_later(RuntimeError, "A")
1927
@worker.start

0 commit comments

Comments
 (0)