Skip to content

Commit

Permalink
Fix memory leakage in kit.PayloadUnaryServerInterceptor (#501)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
r3code committed Jul 14, 2022
1 parent 6aeac52 commit 7fdae0e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions logging/kit/payload_interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 7fdae0e

Please sign in to comment.