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

Return RetriableRequestException for Netty Max Active Stream error #1001

Merged
merged 6 commits into from
May 24, 2024
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 @@ -19,6 +19,7 @@


import com.linkedin.r2.RemoteInvocationException;
import com.linkedin.r2.RetriableRequestException;
import com.linkedin.r2.message.Request;
import com.linkedin.r2.message.rest.RestException;
import com.linkedin.r2.message.rest.RestRequest;
Expand All @@ -42,6 +43,9 @@
*/
public class HttpBridge
{
private static final String NETTY_MAX_ACTIVE_STREAM_ERROR_MESSAGE =
"Maximum active streams violated for this endpoint";

/**
* Wrap application callback for incoming RestResponse with a "generic" HTTP callback.
*
Expand Down Expand Up @@ -149,11 +153,21 @@ public void onResponse(TransportResponse<StreamResponse> response)
{
if (response.hasError())
{
response =
TransportResponseImpl.error(new RemoteInvocationException("Failed to get response from server for URI "
+ uri,
response.getError()),
response.getWireAttributes());
Throwable responseError = response.getError();
// If the error is due to the netty max active stream error, return a RetriableRequestException
if (shouldReturnRetriableRequestException(responseError))
{
StreamException streamException = (StreamException) responseError;
xt-dev marked this conversation as resolved.
Show resolved Hide resolved
response = TransportResponseImpl.error(
new RetriableRequestException("Failed to get response from server for URI " + uri, streamException),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid duplicating the exception message?

RemoteInvocationException wrapException(String message, Throwable exception) {
  if (shouldReturnRetriableRequestException(exception)) {
    return new RetriableRequestException(message, exception);
  } else {
    return new RemoteInvocationException(message, exception);
  }
}

response.getWireAttributes());
}
else
{
response = TransportResponseImpl.error(
new RemoteInvocationException("Failed to get response from server for URI " + uri, responseError),
response.getWireAttributes());
}
}
else if (!RestStatus.isOK(response.getResponse().getStatus()))
{
Expand Down Expand Up @@ -209,6 +223,12 @@ public void onResponse(TransportResponse<StreamResponse> response)
};
}

private static boolean shouldReturnRetriableRequestException(Throwable responseError)
{
return responseError instanceof StreamException && responseError.getMessage()
xt-dev marked this conversation as resolved.
Show resolved Hide resolved
.contains(NETTY_MAX_ACTIVE_STREAM_ERROR_MESSAGE);
}

/**
* Gets the URI to display in exception messages. The query parameters part of the URI is omitted to prevent
* displaying sensitive information.
Expand Down