Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MM-54562] Add panic recover to API handler #547

Merged
merged 1 commit into from
Oct 11, 2023
Merged

[MM-54562] Add panic recover to API handler #547

merged 1 commit into from
Oct 11, 2023

Conversation

streamer45
Copy link
Collaborator

@streamer45 streamer45 commented Oct 6, 2023

Summary

We add a recover function to catch panics at the API level.

  • A panic at this level won't cause the plugin to crash and potentially kill all running calls in the process.
  • We get to log the stack trace at the error level and cleaned up correctly.

Example output:

{"timestamp":"2023-10-06 12:22:22.474 -06:00","level":"error","msg":"panic: runtime error: invalid memory address or nil pointer dereference","caller":"app/plugin_api.go:984","plugin_id":"com.mattermost.calls","origin":"main.(*Plugin).logPanic log.go:22"}
{"timestamp":"2023-10-06 12:22:22.474 -06:00","level":"error","msg":"goroutine 84 [running]:","caller":"app/plugin_api.go:984","plugin_id":"com.mattermost.calls","origin":"main.(*Plugin).logPanic log.go:25"}
{"timestamp":"2023-10-06 12:22:22.474 -06:00","level":"error","msg":"runtime/debug.Stack()","caller":"app/plugin_api.go:984","plugin_id":"com.mattermost.calls","origin":"main.(*Plugin).logPanic log.go:25"}
{"timestamp":"2023-10-06 12:22:22.474 -06:00","level":"error","msg":"runtime/debug/stack.go:24 +0x6b","caller":"app/plugin_api.go:984","plugin_id":"com.mattermost.calls","origin":"main.(*Plugin).logPanic log.go:25"}
{"timestamp":"2023-10-06 12:22:22.475 -06:00","level":"error","msg":"main.(*Plugin).logPanic(0xc0000fc400, {0x1497980, 0x1d996a0})","caller":"app/plugin_api.go:984","plugin_id":"com.mattermost.calls","origin":"main.(*Plugin).logPanic log.go:25"}
{"timestamp":"2023-10-06 12:22:22.475 -06:00","level":"error","msg":"github.com/mattermost/mattermost-plugin-calls/server/log.go:24 +0xca","caller":"app/plugin_api.go:984","plugin_id":"com.mattermost.calls","origin":"main.(*Plugin).logPanic log.go:25"}
{"timestamp":"2023-10-06 12:22:22.475 -06:00","level":"error","msg":"main.(*Plugin).ServeHTTP.func1()","caller":"app/plugin_api.go:984","plugin_id":"com.mattermost.calls","origin":"main.(*Plugin).logPanic log.go:25"}
{"timestamp":"2023-10-06 12:22:22.475 -06:00","level":"error","msg":"github.com/mattermost/mattermost-plugin-calls/server/api.go:518 +0x49","caller":"app/plugin_api.go:984","plugin_id":"com.mattermost.calls","origin":"main.(*Plugin).logPanic log.go:25"}
{"timestamp":"2023-10-06 12:22:22.475 -06:00","level":"error","msg":"panic({0x1497980?, 0x1d996a0?})","caller":"app/plugin_api.go:984","plugin_id":"com.mattermost.calls","origin":"main.(*Plugin).logPanic log.go:25"}
{"timestamp":"2023-10-06 12:22:22.475 -06:00","level":"error","msg":"runtime/panic.go:920 +0x290","caller":"app/plugin_api.go:984","plugin_id":"com.mattermost.calls","origin":"main.(*Plugin).logPanic log.go:25"}

Ticket Link

https://mattermost.atlassian.net/browse/MM-54562

@streamer45 streamer45 added the 2: Dev Review Requires review by a core committer label Oct 6, 2023
@streamer45 streamer45 requested a review from cpoile October 6, 2023 18:34
@streamer45 streamer45 self-assigned this Oct 6, 2023
@codecov-commenter
Copy link

Codecov Report

Attention: 9 lines in your changes are missing coverage. Please review.

Comparison is base (ca763c1) 5.32% compared to head (6f4db3a) 5.33%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff            @@
##            main    #547      +/-   ##
========================================
+ Coverage   5.32%   5.33%   +0.01%     
========================================
  Files         24      24              
  Lines       4469    4479      +10     
========================================
+ Hits         238     239       +1     
- Misses      4214    4222       +8     
- Partials      17      18       +1     
Files Coverage Δ
server/api.go 1.48% <25.00%> (+0.20%) ⬆️
server/log.go 0.00% <0.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@cpoile cpoile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems simple enough, nice addition.

@cpoile cpoile added 3: Reviews Complete All reviewers have approved the pull request and removed 2: Dev Review Requires review by a core committer labels Oct 10, 2023
@streamer45 streamer45 added this to the v0.21.0 / MM 9.3 milestone Oct 11, 2023
@streamer45 streamer45 merged commit d834de2 into main Oct 11, 2023
@streamer45 streamer45 deleted the MM-54562 branch October 11, 2023 22:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3: Reviews Complete All reviewers have approved the pull request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants