From 7fdae0e41d217c2e2240858a53a30c303746bf03 Mon Sep 17 00:00:00 2001 From: "Dmitriy S. Sinyavskiy" Date: Fri, 15 Jul 2022 02:58:27 +0300 Subject: [PATCH] Fix memory leakage in kit.PayloadUnaryServerInterceptor (#501) * Fix memory leakage in kit.PayloadUnaryServerInterceptor Closes issue #498 A wrong assign creates multiple object for GC, and with every call appends new objects, so GC have to walk through thousands of objects. This causes high increasing memory and CPU usage. We saw in our services that it leads to CPU throttling and increasing of a memory usage. * Fix logging in PayloadUnaryServerInterceptor Issue #498 --- logging/kit/payload_interceptors.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/logging/kit/payload_interceptors.go b/logging/kit/payload_interceptors.go index 5dc8031c8..f4b4549b0 100644 --- a/logging/kit/payload_interceptors.go +++ b/logging/kit/payload_interceptors.go @@ -31,11 +31,11 @@ func PayloadUnaryServerInterceptor(logger log.Logger, decider grpc_logging.Serve return handler(ctx, req) } // Use the provided log.Logger for logging but use the fields from context. - logger = log.With(logger, append(serverCallFields(info.FullMethod), ctxkit.TagsToFields(ctx)...)...) - logProtoMessageAsJson(logger, req, "grpc.request.content", "server request payload logged as grpc.request.content field") + logEntry := log.With(logger, append(serverCallFields(info.FullMethod), ctxkit.TagsToFields(ctx)...)...) + logProtoMessageAsJson(logEntry, req, "grpc.request.content", "server request payload logged as grpc.request.content field") resp, err := handler(ctx, req) if err == nil { - logProtoMessageAsJson(logger, resp, "grpc.response.content", "server response payload logged as grpc.request.content field") + logProtoMessageAsJson(logEntry, resp, "grpc.response.content", "server response payload logged as grpc.request.content field") } return resp, err }