From 9ce75d4805784285e6e81e2e39610212614003b0 Mon Sep 17 00:00:00 2001 From: icey-yu <1186114839@qq.com> Date: Thu, 12 Dec 2024 16:52:03 +0800 Subject: [PATCH] fix: rpc recover --- mw/rpc_server_interceptor.go | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/mw/rpc_server_interceptor.go b/mw/rpc_server_interceptor.go index 7d277f0..2ffd4ec 100644 --- a/mw/rpc_server_interceptor.go +++ b/mw/rpc_server_interceptor.go @@ -1,17 +1,3 @@ -// Copyright © 2023 OpenIM. All rights reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - package mw import ( @@ -47,6 +33,11 @@ func RpcServerInterceptor(ctx context.Context, req any, info *grpc.UnaryServerIn return nil, err } + defer func() { + if r := recover(); r != nil { + log.ZPanic(ctx, "RpcServerInterceptor panic", r) + } + }() resp, err := handler(ctx, req) if err != nil { return nil, handleError(ctx, funcName, req, err)