Skip to content

Commit

Permalink
grpc: free incoming request bufferslice after unary processing
Browse files Browse the repository at this point in the history
  • Loading branch information
coxley committed Aug 29, 2024
1 parent 55d820d commit 0941401
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mem/buffer_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,11 @@ func (s BufferSlice) Materialize() []byte {
}

// MaterializeToBuffer functions like Materialize except that it writes the data
// to a single Buffer pulled from the given BufferPool. As a special case, if the
// input BufferSlice only actually has one Buffer, this function has nothing to
// do and simply returns said Buffer.
// to a single Buffer pulled from the given BufferPool.
//
// As a special case, if the input BufferSlice only actually has one Buffer, this
// function simply increases the refcount before returning said Buffer. Freeing this
// buffer won't release it until the BufferSlice is itself released.
func (s BufferSlice) MaterializeToBuffer(pool BufferPool) Buffer {
if len(s) == 1 {
s[0].Ref()
Expand Down
2 changes: 2 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,8 @@ func (s *Server) processUnaryRPC(ctx context.Context, t transport.ServerTranspor
}
ctx = NewContextWithServerTransportStream(ctx, stream)
reply, appErr := md.Handler(info.serviceImpl, ctx, df, s.opts.unaryInt)
defer d.Free()

if appErr != nil {
appStatus, ok := status.FromError(appErr)
if !ok {
Expand Down

0 comments on commit 0941401

Please sign in to comment.