Skip to content

Commit 37b136f

Browse files
committed
Add support for Go recovered panics
1 parent 17c846b commit 37b136f

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/fluent/plugin/exception_detector.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ def self.supported
9494
].freeze
9595

9696
GO_RULES = [
97+
rule([:start_state, :go_after_panic_recovered],
98+
/\bpanic: .*\[recovered\]$/, :go_after_panic_recovered),
99+
rule([:start_state, :go_after_panic_recovered], /\bpanic: /, :go_after_panic),
97100
rule(:start_state, /\bpanic: /, :go_after_panic),
98101
rule(:start_state, /http: panic serving/, :go_goroutine),
99102
rule(:go_after_panic, /^$/, :go_goroutine),

test/plugin/test_exception_detector.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,30 @@ class ExceptionDetectorTest < Test::Unit::TestCase
262262
created by net/http.(*Server).Serve
263263
/usr/local/go/src/net/http/server.go:2851 +0x2f5
264264
END
265+
266+
GO_RECOVERED = <<END.freeze
267+
panic: foo [recovered]
268+
panic: foo [recovered]
269+
panic: foo [recovered]
270+
panic: foo
271+
272+
goroutine 1 [running]:
273+
main.recoverAndPanic()
274+
/tmp/sandbox1820875720/prog.go:12 +0x34
275+
panic({0x459120, 0x476600})
276+
/usr/local/go-faketime/src/runtime/panic.go:838 +0x207
277+
main.recoverAndPanic()
278+
/tmp/sandbox1820875720/prog.go:12 +0x34
279+
panic({0x459120, 0x476600})
280+
/usr/local/go-faketime/src/runtime/panic.go:838 +0x207
281+
main.recoverAndPanic()
282+
/tmp/sandbox1820875720/prog.go:12 +0x34
283+
panic({0x459120, 0x476600})
284+
/usr/local/go-faketime/src/runtime/panic.go:838 +0x207
285+
main.main()
286+
/tmp/sandbox1820875720/prog.go:7 +0x5d
287+
END
288+
265289
CSHARP_EXC = <<END.freeze
266290
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
267291
at System.Collections.Generic.Dictionary`2[System.String,System.Collections.Generic.Dictionary`2[System.Int32,System.Double]].get_Item (System.String key) [0x00000] in <filename unknown>:0
@@ -635,6 +659,7 @@ def test_go
635659
check_exception(GO_ON_GAE_EXC, false)
636660
check_exception(GO_SIGNAL_EXC, false)
637661
check_exception(GO_HTTP, false)
662+
check_exception(GO_RECOVERED, false)
638663
end
639664

640665
def test_ruby

0 commit comments

Comments
 (0)