Skip to content
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

Do not abort CI Visibility spans dispatch on interrupt #6926

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import datadog.trace.util.AgentProxySelector;
import java.io.File;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.ConnectException;
import java.net.InetSocketAddress;
import java.net.Proxy;
Expand Down Expand Up @@ -356,31 +357,45 @@ public void writeTo(BufferedSink sink) throws IOException {
}
}

/**
* Retries a request in accordance with the provided retry policy. <strong>Important:</strong>
* interrupts to a thread executing this method are ignored (the thread's interruption flag is
* restored on exit)
*/
public static Response sendWithRetries(
OkHttpClient httpClient, HttpRetryPolicy retryPolicy, Request request) throws IOException {
while (true) {
try {
okhttp3.Response response = httpClient.newCall(request).execute();
if (response.isSuccessful()) {
return response;
}
if (!retryPolicy.shouldRetry(response)) {
return response;
} else {
closeQuietly(response);
boolean interrupted = false;
try {

while (true) {
try {
Response response = httpClient.newCall(request).execute();
if (response.isSuccessful()) {
return response;
}
if (!retryPolicy.shouldRetry(response)) {
return response;
} else {
closeQuietly(response);
}
} catch (ConnectException | InterruptedIOException ex) {
if (!retryPolicy.shouldRetry(null)) {
throw ex;
}
}
} catch (ConnectException ex) {
if (!retryPolicy.shouldRetry(null)) {
throw ex;
// If we get here, there has been an error, and we still have retries left
long backoffMs = retryPolicy.backoff();
try {
Thread.sleep(backoffMs);
} catch (InterruptedException e) {
// remember interrupted status to restore the thread's interrupted flag later
interrupted = true;
}
}
// If we get here, there has been an error, and we still have retries left
long backoffMs = retryPolicy.backoff();
try {
Thread.sleep(backoffMs);
} catch (InterruptedException e) {

} finally {
if (interrupted) {
Thread.currentThread().interrupt();
throw new IOException(e);
}
}
}
Expand Down
Loading