Skip to content

Commit

Permalink
core: touch() buffer when detach()ing
Browse files Browse the repository at this point in the history
Detachable lets a buffer outlive its original lifetime. The new lifetime
is application-controlled. If the application fails to read/close the
stream, then the leak detector wouldn't make clear what code was
responsible for the buffer's lifetime. With this touch, we'll be able to
see detach() was called and thus know the application needs debugging.

Realized when looking at b/364531464, although I think the issue is
unrelated.
  • Loading branch information
ejona86 committed Sep 5, 2024
1 parent 8adfbf9 commit 721d063
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/io/grpc/internal/ReadableBuffers.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ public ByteBuffer getByteBuffer() {
public InputStream detach() {
ReadableBuffer detachedBuffer = buffer;
buffer = buffer.readBytes(0);
detachedBuffer.touch();
return new BufferInputStream(detachedBuffer);
}

Expand Down

0 comments on commit 721d063

Please sign in to comment.