Skip to content

Commit

Permalink
Add support for Go recovered panics
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparjarek committed Sep 17, 2022
1 parent 17c846b commit 37b136f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/fluent/plugin/exception_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ def self.supported
].freeze

GO_RULES = [
rule([:start_state, :go_after_panic_recovered],
/\bpanic: .*\[recovered\]$/, :go_after_panic_recovered),
rule([:start_state, :go_after_panic_recovered], /\bpanic: /, :go_after_panic),
rule(:start_state, /\bpanic: /, :go_after_panic),
rule(:start_state, /http: panic serving/, :go_goroutine),
rule(:go_after_panic, /^$/, :go_goroutine),
Expand Down
25 changes: 25 additions & 0 deletions test/plugin/test_exception_detector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,30 @@ class ExceptionDetectorTest < Test::Unit::TestCase
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:2851 +0x2f5
END

GO_RECOVERED = <<END.freeze
panic: foo [recovered]
panic: foo [recovered]
panic: foo [recovered]
panic: foo
goroutine 1 [running]:
main.recoverAndPanic()
/tmp/sandbox1820875720/prog.go:12 +0x34
panic({0x459120, 0x476600})
/usr/local/go-faketime/src/runtime/panic.go:838 +0x207
main.recoverAndPanic()
/tmp/sandbox1820875720/prog.go:12 +0x34
panic({0x459120, 0x476600})
/usr/local/go-faketime/src/runtime/panic.go:838 +0x207
main.recoverAndPanic()
/tmp/sandbox1820875720/prog.go:12 +0x34
panic({0x459120, 0x476600})
/usr/local/go-faketime/src/runtime/panic.go:838 +0x207
main.main()
/tmp/sandbox1820875720/prog.go:7 +0x5d
END

CSHARP_EXC = <<END.freeze
System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
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
Expand Down Expand Up @@ -635,6 +659,7 @@ def test_go
check_exception(GO_ON_GAE_EXC, false)
check_exception(GO_SIGNAL_EXC, false)
check_exception(GO_HTTP, false)
check_exception(GO_RECOVERED, false)
end

def test_ruby
Expand Down

0 comments on commit 37b136f

Please sign in to comment.