Refine search
@Override public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (response.getStatusCode() == TOO_MANY_REQUESTS) { return backoffHandler.shouldRetryRequest(command, response); } else { return false; } } }
private boolean ifReplayableBackoffAndReturnTrue(HttpCommand command) { command.incrementFailureCount(); if (!command.isReplayable()) { logger.error("Cannot retry after server error, command is not replayable: %1$s", command); return false; } else if (command.getFailureCount() > retryCountLimit) { logger.error("Cannot retry after server error, command has exceeded retry limit %1$d: %2$s", retryCountLimit, command); return false; } else { imposeBackoffExponentialDelay(command.getFailureCount(), "server error: " + command.toString()); return true; } }
public boolean shouldRetryRequest(HttpCommand command, IOException error) { return ifReplayableBackoffAndReturnTrue(command); }
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (command.getFailureCount() > retryCountLimit) return false; if (response.getStatusCode() == 404 && command.getCurrentRequest().getMethod().equals("DELETE")) { command.incrementFailureCount(); return true; } else if (response.getStatusCode() == 409) { byte[] content = HttpUtils.closeClientButKeepContentStream(response); // Content can be null in the case of HEAD requests if (content != null) { try { AtmosError error = utils.parseAtmosErrorFromContent(command, response, new String(content)); if (error.getCode() == 1006) { return backoffHandler.shouldRetryRequest(command, response); } // don't increment count before here, since backoff handler does already command.incrementFailureCount(); } catch (HttpException e) { logger.warn(e, "error parsing response: %s", new String(content)); } } else { command.incrementFailureCount(); } return true; } return false; }
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (command.getFailureCount() > retryCountLimit) return false; if (response.getStatusCode() == 400 && command.getCurrentRequest().getMethod().equals("PUT") && command.getCurrentRequest().getEndpoint().getPath().indexOf("sandboxes") != -1) { if (response.getPayload() != null) { String error = new String(closeClientButKeepContentStream(response)); if (error != null && error.indexOf("was not uploaded") != -1) { return backoffLimitedRetryHandler.shouldRetryRequest(command, response); } } } return false; }
@Override public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { boolean retry = false; // default try { if (response.getStatusCode() == 401) { closeClientButKeepContentStream(response); logger.debug("invalidating session"); authenticationResponseCache.invalidateAll(); retry = super.shouldRetryRequest(command, response); } return retry; } finally { releasePayload(response); } }
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { byte[] content = HttpUtils.closeClientButKeepContentStream(response); command.incrementFailureCount(); if (!command.isReplayable()) { logger.warn("Cannot retry after server error, command is not replayable: %1$s", command); return false; } else if (command.getFailureCount() > retryCountLimit) { logger.warn( "Cannot retry after server error, command has exceeded retry limit %1$d: %2$s", retryCountLimit, command); return false; } else if (response.getStatusCode() == 409) { // Content can be null in the case of HEAD requests if (content != null) { try { AzureStorageError error = utils.parseAzureStorageErrorFromContent(command, response, new ByteArrayInputStream(content)); if ("ContainerBeingDeleted".equals(error.getCode())) { backoffHandler.imposeBackoffExponentialDelay(100L, 3, retryCountLimit, command .getFailureCount(), command.toString()); return true; } } catch (HttpException e) { logger.warn(e, "error parsing response: %s", new String(content)); } } } return false; }
@Override public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (response.getFirstHeaderOrNull(HttpHeaders.LOCATION) == null && (response.getStatusCode() == 301 || response.getStatusCode() == 307)) { command.incrementRedirectCount(); closeClientButKeepContentStream(response); AWSError error = utils.parseAWSErrorFromContent(command.getCurrentRequest(), response); String host = error.getDetails().get("Endpoint"); if (host != null) { if (host.equals(command.getCurrentRequest().getEndpoint().getHost())) { // must be an amazon error related to // http://developer.amazonwebservices.com/connect/thread.jspa?messageID=72287𑩟 return backoffHandler.shouldRetryRequest(command, response); } else { URI newHost = uriBuilder(command.getCurrentRequest().getEndpoint()).host(host).build(); command.setCurrentRequest(command.getCurrentRequest().toBuilder().endpoint(newHost).build()); } return true; } else { return false; } } else { return super.shouldRetryRequest(command, response); } } }
@Override public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { // Only consider retryable errors and discard rate limit ones if (response.getStatusCode() != 429 || isRateLimitError(response)) { return false; } try { // Note that this will consume the response body. At this point, // subsequent retry handlers or error handlers will not be able to read // again the payload, but that should only be attempted when the // command is not retryable and an exception should be thrown. Error error = parseError.apply(response); logger.debug("processing error: %s", error); boolean isRetryable = RETRYABLE_ERROR_CODE.equals(error.details().code()); return isRetryable ? super.shouldRetryRequest(command, response) : false; } catch (Exception ex) { // If we can't parse the error, just assume it is not a retryable error logger.warn("could not parse error. Request won't be retried: %s", ex.getMessage()); return false; } }
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { closeClientButKeepContentStream(response); if (!command.isReplayable()) { logger.error("Cannot retry after redirect, command is not replayable: %s", command); return false; if (command.incrementRedirectCount() > retryCountLimit) { logger.error("Cannot retry after redirect, command exceeded retry limit %d: %s", retryCountLimit, command); return false; String location = response.getFirstHeaderOrNull(LOCATION); if (location == null) { logger.error("Cannot retry after redirect, no host header: %s", command); return false; HttpRequest current = command.getCurrentRequest(); URI redirect = URI.create(location); if (!redirect.isAbsolute()) { backoffHandler.imposeBackoffExponentialDelay(command.getRedirectCount(), "redirect: " + command.toString()); } else if (current.getFirstHeaderOrNull(HOST) != null && redirect.getHost() != null) { String host = redirect.getPort() > 0 ? redirect.getHost() + ":" + redirect.getPort() : redirect.getHost();
@Test(dataProvider = "codes") public void test409DoesBackoffAndRetryForCode(String code) { AWSUtils utils = createMock(AWSUtils.class); BackoffLimitedRetryHandler backoffLimitedRetryHandler = createMock(BackoffLimitedRetryHandler.class); HttpCommand command = createMock(HttpCommand.class); HttpRequest putBucket = HttpRequest.builder().method(PUT) .endpoint("https://adriancole-blobstore113.s3.amazonaws.com/").build(); HttpResponse operationAborted = HttpResponse.builder().statusCode(CONFLICT.getStatusCode()) .payload(Payloads.newStringPayload(String.format("<Error><Code>%s</Code></Error>", code))).build(); expect(command.getCurrentRequest()).andReturn(putBucket); AWSError error = new AWSError(); error.setCode(code); expect(utils.parseAWSErrorFromContent(putBucket, operationAborted)).andReturn(error); expect(backoffLimitedRetryHandler.shouldRetryRequest(command, operationAborted)).andReturn(Boolean.TRUE); replay(utils, backoffLimitedRetryHandler, command); AWSClientErrorRetryHandler retry = new AWSClientErrorRetryHandler(utils, backoffLimitedRetryHandler, ImmutableSet.<String> of("RequestTimeout", "OperationAborted", "SignatureDoesNotMatch")); assert retry.shouldRetryRequest(command, operationAborted); verify(utils, backoffLimitedRetryHandler, command); }
@Override public boolean shouldRetryRequest(HttpCommand command, IOException error) { HttpRequest request = command.getCurrentRequest(); if ("POST".equals(request.getMethod())) { Payload payload = request.getPayload(); if (!payload.getRawContent().toString().contains(DESCRIBE_ACTION)){ logger.error("Command not considered safe to retry because request method is POST and action may not be idempotent: %1$s", command); return false; } } return super.shouldRetryRequest(command, error); }
@Test void testIncrementsFailureCount() throws InterruptedException, IOException, SecurityException, NoSuchMethodException { HttpCommand command = createCommand(); HttpResponse response = HttpResponse.builder().statusCode(400).build(); handler.shouldRetryRequest(command, response); assertEquals(command.getFailureCount(), 1); handler.shouldRetryRequest(command, response); assertEquals(command.getFailureCount(), 2); handler.shouldRetryRequest(command, response); assertEquals(command.getFailureCount(), 3); }
@Test void testDisallowsExcessiveRetries() throws InterruptedException, IOException, SecurityException, NoSuchMethodException { HttpCommand command = createCommand(); HttpResponse response = HttpResponse.builder().statusCode(400).build(); assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 1 assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 2 assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 3 assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 4 assertEquals(handler.shouldRetryRequest(command, response), true); // Failure 5 assertEquals(handler.shouldRetryRequest(command, response), false); // Failure 6 }
protected boolean shouldRetryRequestOnError(HttpCommand command, HttpResponse response, AWSError error) { if (retryableCodes.contains(error.getCode())) return backoffLimitedRetryHandler.shouldRetryRequest(command, response); return false; }
public void imposeBackoffExponentialDelay(long period, int pow, int failureCount, int max, String commandDescription) { imposeBackoffExponentialDelay(period, period * 10l, pow, failureCount, max, commandDescription); }
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (command.getFailureCount() > retryCountLimit) { return false; } if (response.getStatusCode() == 500) { byte[] content = HttpUtils.closeClientButKeepContentStream(response); // Content can be null in the case of HEAD requests if (content != null) { try { AtmosError error = utils.parseAtmosErrorFromContent(command, response, new String(content)); if (error.getCode() == 1040) { // The server is busy. Please try again. return backoffHandler.shouldRetryRequest(command, response); } // don't increment count before here, since backoff handler does already command.incrementFailureCount(); } catch (HttpException e) { logger.warn(e, "error parsing response: %s", new String(content)); } } else { command.incrementFailureCount(); } return false; } return false; }
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { if (command.getFailureCount() > retryCountLimit) return false; if (response.getStatusCode() == 400 && command.getCurrentRequest().getMethod().equals("PUT") && command.getCurrentRequest().getEndpoint().getPath().indexOf("sandboxes") != -1) { if (response.getPayload() != null) { String error = new String(closeClientButKeepContentStream(response)); if (error != null && error.indexOf("was not uploaded") != -1) { return backoffLimitedRetryHandler.shouldRetryRequest(command, response); } } } return false; }
@Override public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { boolean retry = false; // default try { byte[] data = closeClientButKeepContentStream(response); String message = data != null ? new String(data) : null; if (response.getStatusCode() == 401 || (message != null && message.indexOf(IP_MISMATCH) != -1)) { logger.debug("invalidating session"); sessionCache.invalidateAll(); retry = super.shouldRetryRequest(command, response); } return retry; } finally { releasePayload(response); } }
public boolean shouldRetryRequest(HttpCommand command, HttpResponse response) { byte[] content = HttpUtils.closeClientButKeepContentStream(response); command.incrementFailureCount(); if (!command.isReplayable()) { logger.warn("Cannot retry after server error, command is not replayable: %1$s", command); return false; } else if (command.getFailureCount() > retryCountLimit) { logger.warn( "Cannot retry after server error, command has exceeded retry limit %1$d: %2$s", retryCountLimit, command); return false; } else if (response.getStatusCode() == 409) { // Content can be null in the case of HEAD requests if (content != null) { try { AzureStorageError error = utils.parseAzureStorageErrorFromContent(command, response, new ByteArrayInputStream(content)); if ("ContainerBeingDeleted".equals(error.getCode())) { backoffHandler.imposeBackoffExponentialDelay(100L, 3, retryCountLimit, command .getFailureCount(), command.toString()); return true; } } catch (HttpException e) { logger.warn(e, "error parsing response: %s", new String(content)); } } } return false; }