GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: connection closed prematurely in BlobReadChannel & ConnectionReset by frankyn · Pull Request #173 · googleapis/java-storage

This repository was archived by the owner on Sep 25, 2026. It is now read-only.

Conversation

@frankyn

@frankyn frankyn commented Mar 11, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Fixes #165

Introduce:

  • public StorageException(int code, String message, String reason, Throwable cause):
    to capture the reason which is used to check RETRYABLE_ERRORS.
  • public static StorageException translate(IOException exception): to help translate idempotent request exceptions in case they're RETRYABLE_ERRORS. This translate method should be introduced for other idempotent requests, but that's out of scope for this request.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Frank Natividad
fix: connection closed prematurely
3803ac9
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Mar 11, 2020
@frankyn
frankyn requested review from JesseLovelace and chingor13 March 11, 2020 02:52
@codecov

codecov Bot commented Mar 11, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

Merging #173 into master will increase coverage by 0.01%.
The diff coverage is 66.66%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #173      +/-   ##
============================================
+ Coverage     63.46%   63.48%   +0.01%     
- Complexity      537      540       +3     
============================================
  Files            30       30              
  Lines          4752     4760       +8     
  Branches        427      428       +1     
============================================
+ Hits           3016     3022       +6     
- Misses         1576     1577       +1     
- Partials        160      161       +1
Impacted Files Coverage Δ Complexity Δ
...om/google/cloud/storage/spi/v1/HttpStorageRpc.java 1.63% <0%> (ø) 1 <0> (ø) ⬇️
...ava/com/google/cloud/storage/StorageException.java 92.3% <75%> (-7.7%) 9 <3> (+3)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1617c40...e918305. Read the comment docs.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Frank Natividad added 3 commits March 10, 2020 22:18
Frank Natividad
add connection reset retry
0baa6aa
Frank Natividad
remove integration test
9c01f15
Frank Natividad
format
c5938b9
@frankyn frankyn changed the title fix: connection closed prematurely in BlobReadChannel fix: connection closed prematurely in BlobReadChannel & ConnectionReset Mar 11, 2020
@frankyn
frankyn requested a review from elharo March 11, 2020 16:35
Frank Natividad
clean up tests
1246212
elharo
elharo reviewed Mar 11, 2020
View reviewed changes
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java Outdated
} else if (serviceException.getMessage().contains("Connection closed prematurely")) {
serviceException = new StorageException(new SocketException(serviceException.getMessage()));
} else if (serviceException.getMessage().contains("Connection reset")) {
serviceException = new StorageException(new SocketException(serviceException.getMessage()));

@elharo elharo Mar 11, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This loses the stack trace; you should include the servieException too

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java Outdated
if (serviceException.getCode() == SC_REQUESTED_RANGE_NOT_SATISFIABLE) {
return Tuple.of(null, new byte[0]);
} else if (serviceException.getMessage().contains("Connection closed prematurely")) {
serviceException = new StorageException(new SocketException(serviceException.getMessage()));

@elharo elharo Mar 11, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very weird. I don't think I've ever seen this double wrapping in one throw clause done before. Can you explain the purpose here and how it works?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-storage/src/test/java/com/google/cloud/storage/BlobReadChannelTest.java Outdated

@Test
public void testCreateRetryableErrorPrematureClosure() throws IOException {
byte[] arr = {0x0, 0xd, 0xa};

@elharo elharo Mar 11, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array (no abbreviations per Google style)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-storage/src/test/java/com/google/cloud/storage/BlobReadChannelTest.java Outdated

@Test
public void testCreateNonRetryableErrorPrematureClosure() throws IOException {
byte[] arr = {0x0, 0xd, 0xa};

@elharo elharo Mar 11, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-storage/src/test/java/com/google/cloud/storage/BlobReadChannelTest.java Outdated
expect(storageRpcMock.read(BLOB_ID.toPb(), EMPTY_RPC_OPTIONS, 0, 2097152)).andThrow(exception);
replay(storageRpcMock);
try {
assertTrue(reader.read(byteBuffer) > 0);

@elharo elharo Mar 11, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't both assertTrue and fail

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Frank Natividad
change design of transient retry strategy
42d95a4
@frankyn
frankyn force-pushed the fix-premature-closure branch from 47fc04c to 42d95a4 Compare March 12, 2020 00:15
crwilcox
crwilcox reviewed Mar 12, 2020
View reviewed changes
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/StorageException.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java Outdated
}

private static StorageException translate(IOException exception) {

@crwilcox crwilcox Mar 12, 2020

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we run a formatter for java? Is this blank line a problem for it?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Mar 12, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't clean it up surprisingly.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Frank Natividad added 2 commits March 11, 2020 17:26
Frank Natividad
add documentation
fb31431
Frank Natividad
format docs
ffd7b1f
@frankyn
frankyn requested review from crwilcox and elharo and removed request for chingor13 March 12, 2020 00:36
crwilcox
crwilcox approved these changes Mar 12, 2020
View reviewed changes
@frankyn
frankyn requested a review from chingor13 March 12, 2020 00:55
elharo
elharo reviewed Mar 12, 2020
View reviewed changes
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/StorageException.java
@@ -43,7 +46,9 @@ public final class StorageException extends BaseHttpServiceException {
new Error(500, null),

@elharo elharo Mar 12, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this Error class come from?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Mar 12, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://github.com/googleapis/java-core/blob/master/google-cloud-core/src/main/java/com/google/cloud/BaseServiceException.java#L174

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@elharo elharo Mar 12, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this had not been static imported, I probably could have figured that out...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@elharo elharo Mar 12, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also that's marked @InternalApi so it shouldn't be used here at all.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Mar 12, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StorageException is also annotated with @InternalApi. I'm not introducing the use Error(). I think this is okay, as Storage isn't the only library using the base class BaseHttpServiceException, e.g. Bigquery.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@chingor13 chingor13 Mar 12, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For @InternalApi from google-cloud-core, it's public because it needs to be, but intended for use by our libraries

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@elharo elharo Mar 12, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll live with it this PR, but that's a major abuse of @InternalApi. It's as effectively locked in as any other public API. We should admit what's been done here, and remove @InternalApi from those classes. We can't change them absent an incompatible major version bump. :-(

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/StorageException.java Outdated
}

/**
* Translate IOException to the StorageException that caused the error. This method default to

@elharo elharo Mar 12, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaults

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/StorageException.java Outdated

/**
* Translate IOException to the StorageException that caused the error. This method default to
* idempotent always being {@code True}. This method will force retry of the following transient

@elharo elharo Mar 12, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true? (primitive)
will force --> forces
or perhaps just will force retry of --> retries

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/StorageException.java Outdated
/**
* Translate IOException to the StorageException that caused the error. This method default to
* idempotent always being {@code True}. This method will force retry of the following transient
* issues (Connection Closed Prematurely, Connection Reset).

@elharo elharo Mar 12, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"following" isn't needed; remove parentheses

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/StorageException.java Outdated
* idempotent always being {@code True}. This method will force retry of the following transient
* issues (Connection Closed Prematurely, Connection Reset).
*
* <p>Please Review {@code RETRYABLE_ERRORS} for a full list of retryable errors.

@elharo elharo Mar 12, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewrite without "please Review"
also, never use Please in technical docs per https://developers.google.com/style/tone

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/StorageException.java Outdated
*
* <p>Please Review {@code RETRYABLE_ERRORS} for a full list of retryable errors.
*
* @throws StorageException when {@code ex} was caused by a {@code StorageException}

@elharo elharo Mar 12, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It returns, it doesn't throw

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Frank Natividad
address feedback
5663daf
@frankyn

frankyn commented Mar 12, 2020

Copy link
Copy Markdown
Contributor Author

Thanks @elharo, I addressed your comments.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@frankyn
frankyn requested a review from elharo March 12, 2020 16:18
JesseLovelace
JesseLovelace approved these changes Mar 12, 2020
View reviewed changes
elharo
elharo reviewed Mar 12, 2020
View reviewed changes
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/StorageException.java
@@ -43,7 +46,9 @@ public final class StorageException extends BaseHttpServiceException {
new Error(500, null),

@elharo elharo Mar 12, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this had not been static imported, I probably could have figured that out...

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/StorageException.java
@@ -43,7 +46,9 @@ public final class StorageException extends BaseHttpServiceException {
new Error(500, null),

@elharo elharo Mar 12, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also that's marked @InternalApi so it shouldn't be used here at all.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/StorageException.java Outdated

/**
* Translate IOException to the StorageException that caused the error. This method defaults to
* idempotent always being {@code true}. This method retries the transient issues Connection

@elharo elharo Mar 12, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it retries anything. There's no network connection here.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Mar 12, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah,,, that's not worded well fixing.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/StorageException.java Outdated
}

/**
* Translate IOException to the StorageException that caused the error. This method defaults to

@elharo elharo Mar 12, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to the... --> to a StorageException representing the cause of the error. (otherwise you have the effect coming before the cause.)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/StorageException.java Outdated
* idempotent always being {@code true}. This method retries the transient issues Connection
* Closed Prematurely and Connection Reset.
*
* <p>Review {@code RETRYABLE_ERRORS} for a full list of retryable errors.

@elharo elharo Mar 12, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RETRYABLE_ERRORS is rightly private, but it won't show in API docs.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread google-cloud-storage/src/main/java/com/google/cloud/storage/StorageException.java
*
* @returns {@code StorageException}
*/
public static StorageException translate(IOException exception) {

@elharo elharo Mar 12, 2020

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

translate is an uncommon name for this operation. Perhaps wrap?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@frankyn frankyn Mar 12, 2020

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Translate is what's being used in the code right now and wanted to keep consistent given there's already translateAndThrow

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Frank Natividad
address feedback
e918305
@frankyn
frankyn requested a review from elharo March 12, 2020 18:23
@frankyn
frankyn merged commit 27bccda into master Mar 13, 2020
@frankyn
frankyn deleted the fix-premature-closure branch March 13, 2020 17:18
@frankyn

frankyn commented Mar 13, 2020

Copy link
Copy Markdown
Contributor Author

Merging after discussion with @elharo offline. Two approvals is more than enough for this.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gcf-merge-on-green Bot pushed a commit that referenced this pull request Mar 13, 2020
@release-please
chore: release 1.105.2 (#181)
528a585
🤖 I have created a release \*beep\* \*boop\* 
---
### [1.105.2](https://www.github.com/googleapis/java-storage/compare/v1.105.1...v1.105.2) (2020-03-13)


### Bug Fixes

* connection closed prematurely in BlobReadChannel & ConnectionReset ([#173](https://www.github.com/googleapis/java-storage/issues/173)) ([27bccda](https://www.github.com/googleapis/java-storage/commit/27bccda384da4a7b877b371fbaecc794d6304fbf))


### Dependencies

* update core dependencies ([#171](https://www.github.com/googleapis/java-storage/issues/171)) ([ef5f2c6](https://www.github.com/googleapis/java-storage/commit/ef5f2c6e5079debe8f7f37c3d2c501aac3dc82a6))
---


This PR was generated with [Release Please](https://github.com/googleapis/release-please).
@original-brownbear original-brownbear mentioned this pull request Mar 24, 2020
Upgrade GCS Dependency to 1.106.0 elastic/elasticsearch#54092
Merged
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@chingor13 chingor13 Awaiting requested review from chingor13
@elharo elharo Awaiting requested review from elharo
2 more reviewers
@crwilcox crwilcox crwilcox approved these changes
@JesseLovelace JesseLovelace JesseLovelace approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Tracking bug: com.google.cloud.storage.StorageException: Connection closed prematurely:..

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@frankyn @chingor13 @crwilcox @elharo @JesseLovelace @googlebot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.