From 96e40491fb31c8986f0785a24f6846a9c2aa012c Mon Sep 17 00:00:00 2001 From: BenWhitehead Date: Tue, 10 Sep 2024 16:43:46 -0400 Subject: [PATCH] chore: attempt to drain the stream iterator Related #2696 --- .../GapicUnbufferedReadableByteChannel.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java index ecaa3bc878..7b680dc448 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java @@ -201,8 +201,23 @@ public ReadObjectResponse next() { @Override public void close() { if (serverStream != null) { - // todo: do we need to "drain" anything? serverStream.cancel(); + if (responseIterator != null) { + IOException ioException = null; + while (responseIterator.hasNext()) { + try { + ReadObjectResponse next = responseIterator.next(); + ResponseContentLifecycleHandle handle = rclm.get(next); + handle.close(); + } catch (IOException e) { + if (ioException == null) { + ioException = e; + } else { + ioException.addSuppressed(e); + } + } + } + } } }