diff --git a/grpcall.go b/grpcall.go index a78ce40..e251a9a 100644 --- a/grpcall.go +++ b/grpcall.go @@ -134,13 +134,15 @@ func (this Grpcall) invokeServStream(ctx context.Context, stub grpcdynamic.Stub, go func() { msgParser := jsonpb.Marshaler{ - EmitDefaults: true, + OrigName: true, // 保留原始字段名 + EmitDefaults: true, // 包括默认值的字段也会被序列化 AnyResolver: anyResolver, } defer func() { cancel() pWriter.Close() + pReader.Close() }() for { @@ -467,8 +469,9 @@ func NewGrpcall(addr string, protosets []string, opts ...grpc.DialOption) (g *Gr opts = append(opts, grpc.WithKeepaliveParams(keepalive.ClientParameters{ - Time: 64 * time.Second, - Timeout: 64 * time.Second, + Time: 10 * time.Second, // 心跳包时间间隔 + Timeout: 5 * time.Second, // 心跳包超时时间 + PermitWithoutStream: true, // 允许在没有活动流时发送心跳包 }), grpc.WithBlock(), grpc.FailOnNonTempDialError(true),