mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-09 17:44:59 +09:00
grpc panic recover
This commit is contained in:
parent
f06bc92c8f
commit
db76d0b5dc
4 changed files with 1021 additions and 527 deletions
|
@ -5,13 +5,6 @@ package main
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/anytypeio/go-anytype-middleware/metrics"
|
||||
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
||||
grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
|
||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
"github.com/uber/jaeger-client-go"
|
||||
"net"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
|
@ -20,6 +13,14 @@ import (
|
|||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"github.com/anytypeio/go-anytype-middleware/metrics"
|
||||
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
||||
grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
|
||||
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
||||
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
|
||||
"github.com/opentracing/opentracing-go"
|
||||
"github.com/uber/jaeger-client-go"
|
||||
|
||||
"github.com/anytypeio/go-anytype-middleware/core/event"
|
||||
"github.com/anytypeio/go-anytype-middleware/pb"
|
||||
"github.com/anytypeio/go-anytype-middleware/pkg/lib/logging"
|
||||
|
@ -155,6 +156,23 @@ func main() {
|
|||
streamInterceptors = append(streamInterceptors, otgrpc.OpenTracingStreamServerInterceptor(tracer, streamOptions...))
|
||||
}
|
||||
|
||||
unaryInterceptors = append(unaryInterceptors, func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
mw.OnPanic(r)
|
||||
resp = &pb.RpcGenericErrorResponse{
|
||||
Error: &pb.RpcGenericErrorResponseError{
|
||||
Code: pb.RpcGenericErrorResponseError_UNKNOWN_ERROR,
|
||||
Description: "panic recovered",
|
||||
},
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
resp, err = handler(ctx, req)
|
||||
return resp, err
|
||||
})
|
||||
|
||||
server := grpc.NewServer(grpc.MaxRecvMsgSize(20*1024*1024),
|
||||
grpc.UnaryInterceptor(grpc_middleware.ChainUnaryServer(unaryInterceptors...)),
|
||||
grpc.StreamInterceptor(grpc_middleware.ChainStreamServer(streamInterceptors...)),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue