panichandler

package
v1.68.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2019 License: MIT, MIT Imports: 5 Imported by: 0

README

grpc-panic-handler

Taken from https://github.com/kazegusuri/grpc-panic-handler

grpc-panic-handler is an interceptor to protect a process from aborting by panic and return Internal error as status code.

Usage

import (
	panichandler "github.com/kazegusuri/grpc-panic-handler"
)

func main() {
	uIntOpt := grpc.UnaryInterceptor(panichandler.UnaryPanicHandler)
	sIntOpt := grpc.StreamInterceptor(panichandler.StreamPanicHandler)
	grpc.NewServer(uIntOpt, sIntOpt)
}

Custom Panic Handler

You can write custom panic handler in case of panic. Use InstallPanicHandler.

func main() {
	panichandler.InstallPanicHandler(func(r interface{}) {
		fmt.Printf("panic happened: %v", r)
	}
}
Built-in custom panic handler
  • LogPanicDump
  • debug.Stack() to stderr
  • LogPanicStackMultiLine
  • show stack trace in multi line by glog
AuthorMasahiro Sano
CopyrightCopyright (c) 2016- Masahiro Sano
LicenseMIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InstallPanicHandler

func InstallPanicHandler(handler PanicHandler)

InstallPanicHandler installs additional crash handles for dealing with a panic

func StreamPanicHandler

func StreamPanicHandler(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) (err error)

StreamPanicHandler handles stream panics

func UnaryPanicHandler

func UnaryPanicHandler(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error)

UnaryPanicHandler handles request-response panics

Types

type PanicHandler

type PanicHandler func(methodName string, error interface{})

PanicHandler is a handler that will be called on a grpc panic

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL