Skip to content

Commit 96e4049

Browse files
committed
chore: attempt to drain the stream iterator
Related #2696
1 parent 1855308 commit 96e4049

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

‎google-cloud-storage/src/main/java/com/google/cloud/storage/GapicUnbufferedReadableByteChannel.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,23 @@ public ReadObjectResponse next() {
201201
@Override
202202
public void close() {
203203
if (serverStream != null) {
204-
// todo: do we need to "drain" anything?
205204
serverStream.cancel();
205+
if (responseIterator != null) {
206+
IOException ioException = null;
207+
while (responseIterator.hasNext()) {
208+
try {
209+
ReadObjectResponse next = responseIterator.next();
210+
ResponseContentLifecycleHandle handle = rclm.get(next);
211+
handle.close();
212+
} catch (IOException e) {
213+
if (ioException == null) {
214+
ioException = e;
215+
} else {
216+
ioException.addSuppressed(e);
217+
}
218+
}
219+
}
220+
}
206221
}
207222
}
208223

0 commit comments

Comments
 (0)