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 7b680dc448..8904dce664 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 @@ -182,6 +182,7 @@ public boolean hasNext() { if (!result.isDone()) { result.setException(StorageException.coalesce(e)); } + reset(); throw e; } } @@ -194,6 +195,7 @@ public ReadObjectResponse next() { if (!result.isDone()) { result.setException(StorageException.coalesce(e)); } + reset(); throw e; } } @@ -212,7 +214,7 @@ public void close() { } catch (IOException e) { if (ioException == null) { ioException = e; - } else { + } else if (ioException != e) { ioException.addSuppressed(e); } } @@ -238,5 +240,11 @@ private Iterator ensureResponseIteratorOpen() { } } } + + private void reset() { + serverStream = null; + responseIterator = null; + streamInitialized = false; + } } } diff --git a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageOptions.java b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageOptions.java index 07616d0ef1..90f16bca68 100644 --- a/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageOptions.java +++ b/google-cloud-storage/src/main/java/com/google/cloud/storage/GrpcStorageOptions.java @@ -1098,7 +1098,7 @@ static void closeAllStreams(Iterable inputStreams) throws IOExcepti } catch (IOException e) { if (ioException == null) { ioException = e; - } else { + } else if (ioException != e) { ioException.addSuppressed(e); } }