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

Standardize how we log and handle panics #1692

Merged

Conversation

RebeccaMahany
Copy link
Contributor

@RebeccaMahany RebeccaMahany commented Apr 25, 2024

Requires #1693

If one goroutine panics, all of launcher will terminate. Before termination, the panic will travel up to the top-level function in the executing goroutine. If we want to recover or log panics, we must do that in this top-level function.

This PR introduces gowrapper to wrap our goroutines, to make it easier to standardize recovering from and logging panics. It will always log the panic, and allows for providing an onPanic function that executes if gowrapper recovers from a panic.

This PR adds gowrapper usage to our windows service and to all of our rungroups.

References:

Example logs from panic inside a rungroup
{
  "time":"2024-04-30T14:17:34.976926Z",
  "level":"ERROR",
  "source":{
    "function":"github.com/kolide/launcher/ee/gowrapper.Go.func1.1",
    "file":"/Users/rebeccamahany-horton/Repos/launcher/ee/gowrapper/goroutine.go",
    "line":18
  },
  "msg":"panic occurred in goroutine",
  "launcher_run_id":"01HWQNTJJ3RET2810PM254GV7H",
  "component":"run_group",
  "err":"runtime error: index out of range [3] with length 0"
}
{
  "time":"2024-04-30T14:17:34.983632Z",
  "level":"ERROR",
  "source":{
    "function":"github.com/kolide/launcher/ee/gowrapper.Go.func1.1",
    "file":"/Users/rebeccamahany-horton/Repos/launcher/ee/gowrapper/goroutine.go",
    "line":23
  },
  "msg":"panic stack trace",
  "launcher_run_id":"01HWQNTJJ3RET2810PM254GV7H",
  "component":"run_group",
  "stack_trace":"runtime error: index out of range [3] with length 0\ngitpro.ttaallkk.top/kolide/launcher/ee/gowrapper.Go.func1.1\n\t/Users/rebeccamahany-horton/Repos/launcher/ee/gowrapper/goroutine.go:25\nruntime.gopanic\n\t/usr/local/go/src/runtime/panic.go:914\nruntime.goPanicIndex\n\t/usr/local/go/src/runtime/panic.go:114\ngitpro.ttaallkk.top/kolide/launcher/ee/tuf.(*TufAutoupdater).Execute\n\t/Users/rebeccamahany-horton/Repos/launcher/ee/tuf/autoupdate.go:234\ngitpro.ttaallkk.top/kolide/launcher/pkg/rungroup.(*Group).Run.func1\n\t/Users/rebeccamahany-horton/Repos/launcher/pkg/rungroup/rungroup.go:71\ngitpro.ttaallkk.top/kolide/launcher/ee/gowrapper.Go.func1\n\t/Users/rebeccamahany-horton/Repos/launcher/ee/gowrapper/goroutine.go:33\nruntime.goexit\n\t/usr/local/go/src/runtime/asm_arm64.s:1197"
}
Example logs from panic inside Windows service
{
  "time":"2024-04-30T14:26:47.1429033Z",
  "level":"ERROR",
  "source":{
  "function":
    "github.com/kolide/launcher/ee/gowrapper.Go.func1.1",
    "file":"C:/Users/Becca/Repos/launcher/ee/gowrapper/goroutine.go",
    "line":18
  },
  "msg":"panic occurred in goroutine",
  "launcher_run_id":"01HWQPD75EQTGQFQ4BBZ1FNFGD",
  "err":"runtime error: index out of range [1] with length 0"
}
{
  "time":"2024-04-30T14:26:47.1434689Z",
  "level":"ERROR",
  "source":{
    "function":"github.com/kolide/launcher/ee/gowrapper.Go.func1.1",
    "file":"C:/Users/Becca/Repos/launcher/ee/gowrapper/goroutine.go",
    "line":23
  },
  "msg":"panic stack trace",
  "launcher_run_id":"01HWQPD75EQTGQFQ4BBZ1FNFGD",
  "stack_trace":"runtime error: index out of range [1] with length 0\ngitpro.ttaallkk.top/kolide/launcher/ee/gowrapper.Go.func1.1\n\tC:/Users/Becca/Repos/launcher/ee/gowrapper/goroutine.go:25\nruntime.gopanic\n\tC:/Program Files/Go/src/runtime/panic.go:914\nruntime.goPanicIndex\n\tC:/Program Files/Go/src/runtime/panic.go:114\nmain.runLauncher\n\tC:/Users/Becca/Repos/launcher/cmd/launcher/launcher.go:525\nmain.(*winSvc).Execute.func1\n\tC:/Users/Becca/Repos/launcher/cmd/launcher/svc_windows.go:189\ngitpro.ttaallkk.top/kolide/launcher/ee/gowrapper.Go.func1\n\tC:/Users/Becca/Repos/launcher/ee/gowrapper/goroutine.go:33\nruntime.goexit\n\tC:/Program Files/Go/src/runtime/asm_amd64.s:1650"
}
{
  "time":"2024-04-30T14:26:47.1434689Z",
  "level":"ERROR",
  "source":{
    "function":"main.(*winSvc).Execute.func2",
    "file":"C:/Users/Becca/Repos/launcher/cmd/launcher/svc_windows.go",
    "line":205
  },
  "msg":"exiting after runLauncher panic",
  "launcher_run_id":"01HWQPD75EQTGQFQ4BBZ1FNFGD",
  "err":"runtime error: index out of range [1] with length 0"
}

James-Pickett
James-Pickett previously approved these changes Apr 25, 2024
@RebeccaMahany RebeccaMahany changed the title Log panic in runLauncher call on Windows Log panics Apr 25, 2024
James-Pickett
James-Pickett previously approved these changes Apr 25, 2024
Copy link
Contributor

@James-Pickett James-Pickett left a comment

Choose a reason for hiding this comment

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

LGTM!

@RebeccaMahany RebeccaMahany marked this pull request as ready for review April 30, 2024 15:01
@RebeccaMahany RebeccaMahany changed the title Log panics Standardize how we log and handle panics Apr 30, 2024
zackattack01
zackattack01 previously approved these changes Apr 30, 2024
Copy link
Contributor

@zackattack01 zackattack01 left a comment

Choose a reason for hiding this comment

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

🔥

James-Pickett
James-Pickett previously approved these changes Apr 30, 2024
@RebeccaMahany RebeccaMahany added this pull request to the merge queue Apr 30, 2024
ee/gowrapper/goroutine.go Outdated Show resolved Hide resolved
pkg/rungroup/rungroup.go Show resolved Hide resolved
@directionless directionless removed this pull request from the merge queue due to a manual request Apr 30, 2024
@RebeccaMahany RebeccaMahany added this pull request to the merge queue Apr 30, 2024
Merged via the queue into kolide:main with commit a3335c0 Apr 30, 2024
29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants