mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 14:31:56 +00:00
* First pass at moving moving logging linting into Bazel * fixed negation operators * Update dev/linters/logging/logging.go Co-authored-by: William Bezuidenhout <william.bezuidenhout@sourcegraph.com> * added more exceptions and refactored one or two impls * added nogo lint pragmas to offending files * ran configure * reverted git-combine refactor * ran configure * reverted test as well --------- Co-authored-by: William Bezuidenhout <william.bezuidenhout@sourcegraph.com>
27 lines
727 B
Go
27 lines
727 B
Go
package background
|
|
|
|
import (
|
|
"log" //nolint:logging // Legacy and special case handling of panics in background routines
|
|
"runtime/debug"
|
|
)
|
|
|
|
// Go runs the given function in a goroutine and catches and logs panics.
|
|
//
|
|
// This prevents a single panicking goroutine from crashing the entire binary,
|
|
// which is undesirable for services with many different components, like our
|
|
// frontend service, where one location of code panicking could be catastrophic.
|
|
//
|
|
// More advanced use cases should copy this implementation and modify it.
|
|
func Go(f func()) {
|
|
go func() {
|
|
defer func() {
|
|
if err := recover(); err != nil {
|
|
stack := debug.Stack()
|
|
log.Printf("goroutine panic: %v\n%s", err, stack)
|
|
}
|
|
}()
|
|
|
|
f()
|
|
}()
|
|
}
|