-
Notifications
You must be signed in to change notification settings - Fork 24.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Bug in Azure Repo Exception Handling #47968
Merged
original-brownbear
merged 4 commits into
elastic:master
from
original-brownbear:fix-azure-exeception-handling
Oct 15, 2019
+59
−20
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
778a07e
Fix Bug in Azure Repo Exception Handling
original-brownbear e1c9127
Merge remote-tracking branch 'elastic/master' into fix-azure-execepti…
original-brownbear 6cf65fc
throwables it is :)
original-brownbear 07ab5cd
Merge remote-tracking branch 'elastic/master' into fix-azure-execepti…
original-brownbear File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ | |
import org.junit.Before; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.net.InetAddress; | ||
|
@@ -63,6 +64,7 @@ | |
import java.util.Objects; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
@@ -294,6 +296,44 @@ public void testWriteLargeBlob() throws Exception { | |
assertThat(blocks.isEmpty(), is(true)); | ||
} | ||
|
||
public void testRetryUntilFail() throws IOException { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is admittedly a little random/weird, but I figured it captured the initial issue that showed this bug to some degree at least. |
||
final AtomicBoolean requestReceived = new AtomicBoolean(false); | ||
httpServer.createContext("/container/write_blob_max_retries", exchange -> { | ||
try { | ||
if (requestReceived.compareAndSet(false, true)) { | ||
throw new AssertionError("Should not receive two requests"); | ||
} else { | ||
exchange.sendResponseHeaders(RestStatus.CREATED.getStatus(), -1); | ||
} | ||
} finally { | ||
exchange.close(); | ||
} | ||
}); | ||
|
||
final BlobContainer blobContainer = createBlobContainer(randomIntBetween(2, 5)); | ||
try (InputStream stream = new InputStream() { | ||
|
||
@Override | ||
public int read() throws IOException { | ||
throw new IOException("foo"); | ||
} | ||
|
||
@Override | ||
public boolean markSupported() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void reset() { | ||
throw new AssertionError("should not be called"); | ||
} | ||
}) { | ||
final IOException ioe = expectThrows(IOException.class, () -> | ||
blobContainer.writeBlob("write_blob_max_retries", stream, randomIntBetween(1, 128), randomBoolean())); | ||
assertThat(ioe.getMessage(), is("foo")); | ||
} | ||
} | ||
|
||
private static byte[] randomBlobContent() { | ||
return randomByteArrayOfLength(randomIntBetween(1, frequently() ? 512 : 1 << 20)); // rarely up to 1mb | ||
} | ||
|
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.
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 feels wrong to wrap this as an IOException. Can we just use
Throwables.rethrow(cause)
here?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'd rather not tbh. We could wrap in a different exception but
Throwables.rethrow
itself just casts toRunTimeException
doesn't it? In the end if the SDK ever changes or we missed some checked exception in our code, we'll get the same bug we started from here again won't we?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.
no it does not
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.
Huh, Java works in mysterious ways. Sorry for the noise, my bad seems it works just fine :)
=> used it all the way now.