static Exception distinguishNotFound(final String message) { Pattern p = Pattern.compile("The messaging entity .* could not be found"); Matcher m = p.matcher(message); if (m.find()) { return new IllegalEntityException(message); } else { return new EventHubException(true, String.format(ClientConstants.AMQP_REQUEST_FAILED_ERROR, AmqpResponseCode.NOT_FOUND, message)); } }
public static boolean isRetryableException(Exception exception) { if (exception == null) { throw new IllegalArgumentException("exception cannot be null"); } if (exception instanceof EventHubException) { return ((EventHubException) exception).getIsTransient(); } return false; }
static <T> void completeExceptionally(CompletableFuture<T> future, Exception exception, ErrorContextProvider contextProvider) { if (exception != null && exception instanceof EventHubException) { final ErrorContext errorContext = contextProvider.getContext(); ((EventHubException) exception).setContext(errorContext); } future.completeExceptionally(exception); }
static Exception amqpResponseCodeToException(final int statusCode, final String statusDescription) { final AmqpResponseCode amqpResponseCode = AmqpResponseCode.valueOf(statusCode); if (amqpResponseCode == null) return new EventHubException(true, String.format(ClientConstants.AMQP_REQUEST_FAILED_ERROR, statusCode, statusDescription)); switch (amqpResponseCode) { case BAD_REQUEST: return new IllegalArgumentException(String.format(ClientConstants.AMQP_REQUEST_FAILED_ERROR, statusCode, statusDescription)); case NOT_FOUND: return ExceptionUtil.distinguishNotFound(statusDescription); case FORBIDDEN: return new QuotaExceededException(String.format(ClientConstants.AMQP_REQUEST_FAILED_ERROR, statusCode, statusDescription)); case UNAUTHORIZED: return new AuthorizationFailedException(String.format(ClientConstants.AMQP_REQUEST_FAILED_ERROR, statusCode, statusDescription)); default: return new EventHubException(true, String.format(ClientConstants.AMQP_REQUEST_FAILED_ERROR, statusCode, statusDescription)); } }
private void drainPendingReceives(final Exception exception) { WorkItem<Collection<Message>> workItem; final boolean shouldReturnNull = (exception == null || (exception instanceof EventHubException && ((EventHubException) exception).getIsTransient())); while ((workItem = this.pendingReceives.poll()) != null) { final CompletableFuture<Collection<Message>> future = workItem.getWork(); if (shouldReturnNull) { future.complete(null); } else { ExceptionUtil.completeExceptionally(future, exception, this); } } }
this.onRemoteSessionOpenError.accept( null, new EventHubException( false, String.format("onSessionLocalOpen entityName[%s], underlying IO of reactorDispatcher faulted with error: %s",
@Override public void onError(Throwable throwable) { errorRate.inc(); aggReadErrors.inc(); if (throwable instanceof EventHubException) { EventHubException busException = (EventHubException) throwable; if (busException.getIsTransient()) { LOG.warn( String.format("Received transient exception from EH client. Renew partition receiver for ssp: %s", ssp), throwable); try { // Add a fixed delay so that we don't keep retrying when there are long-lasting failures Thread.sleep(Duration.ofSeconds(2).toMillis()); } catch (InterruptedException e) { LOG.warn("Interrupted during sleep before renew", e); } // Retry creating a receiver since error likely due to timeout renewPartitionReceiver(ssp); return; } } LOG.error(String.format("Received non transient exception from EH client for ssp: %s", ssp), throwable); // Propagate non transient or unknown errors eventHubNonTransientError.set(throwable); } }
@Override public void onClose(ErrorCondition condition) { if (condition == null || condition.getCondition() == null) { this.cancelPendingRequests( new EventHubException( ClientConstants.DEFAULT_IS_TRANSIENT, "The underlying request-response channel closed, recreate the channel and retry the request.")); if (onClose != null) onLinkCloseComplete(null); } else { this.onError(ExceptionUtil.toException(condition)); } }
&& !((EventHubException) completionException).getIsTransient()) { this.cancelOpen(completionException);
? new EventHubException(true, String.format(Locale.US, "Entity(%s): client encountered transient error for unknown reasons, please retry the operation.", this.sendPath)) : completionException;
} else if (exception instanceof EventHubException && !((EventHubException) exception).getIsTransient()) { this.cancelOpen(exception);
? new EventHubException(true, String.format(Locale.US, "Entity(%s): client encountered transient error for unknown reasons, please retry the operation.", this.receivePath)) : exception;
cause); } else { sbException = new EventHubException( true, String.format(Locale.US, "%s, %s", message, ExceptionUtil.getTrackingIDAndTimeToLog()),
this.cleanupFailedSend( pendingSendWorkItem, new EventHubException(false, String.format(Locale.US, "Entity(%s): send operation failed while scheduling a retry on Reactor, see cause for more details.", this.sendPath), this.cleanupFailedSend(pendingSendWorkItem, new OperationCancelledException(outcome.toString())); } else { this.cleanupFailedSend(pendingSendWorkItem, new EventHubException(false, outcome.toString()));
lastException = new EventHubException(true, "timed out"); completeWith = null; } else if (error instanceof Exception) {
return new EventHubException(ClientConstants.DEFAULT_IS_TRANSIENT, new TimeoutException(errorCondition.getDescription())); } else if (errorCondition.getCondition() == ClientConstants.SERVER_BUSY_ERROR) { return new ServerBusyException(errorCondition.getDescription()); return new PayloadSizeExceededException(errorCondition.getDescription()); } else if (errorCondition.getCondition() == AmqpErrorCode.InternalError) { return new EventHubException(true, new AmqpException(errorCondition)); } else if (errorCondition.getCondition() == ClientConstants.ARGUMENT_ERROR) { return new EventHubException(false, errorCondition.getDescription(), new AmqpException(errorCondition)); } else if (errorCondition.getCondition() == ClientConstants.ARGUMENT_OUT_OF_RANGE_ERROR) { return new EventHubException(false, errorCondition.getDescription(), new AmqpException(errorCondition)); } else if (errorCondition.getCondition() == AmqpErrorCode.NotImplemented) { return new UnsupportedOperationException(errorCondition.getDescription()); return new UnsupportedOperationException(errorCondition.getDescription()); } else if (errorCondition.getCondition() == ClientConstants.PARTITION_NOT_OWNED_ERROR) { return new EventHubException(false, errorCondition.getDescription()); } else if (errorCondition.getCondition() == ClientConstants.STORE_LOCK_LOST_ERROR) { return new EventHubException(false, errorCondition.getDescription()); } else if (errorCondition.getCondition() == AmqpErrorCode.AmqpLinkDetachForced) { return new EventHubException(true, new AmqpException(errorCondition)); } else if (errorCondition.getCondition() == AmqpErrorCode.ResourceLimitExceeded) { return new QuotaExceededException(new AmqpException(errorCondition)); return new EventHubException(ClientConstants.DEFAULT_IS_TRANSIENT, errorCondition.getDescription());
new EventHubException(false /* is transient */, "test")); consumer.poll(Collections.singleton(ssp), 0).get(ssp); Assert.assertEquals(consumer.recentRetryAttempts.size(), 0); eventHubClientWrapperFactory.triggerError(consumer.streamPartitionHandlers, new EventHubException(false /* is transient */, "test")); consumer.poll(Collections.singleton(ssp), 0).get(ssp); Assert.assertNotNull("reconnect task should have been submitted", consumer.reconnectTaskStatus); new EventHubException(false /* is transient */, "test")); consumer.poll(Collections.singleton(ssp), 0).get(ssp); Assert.assertEquals("there shouldn't be another retry task within min retry interval", consumer.reconnectTaskStatus, new EventHubException(false /* is transient */, "test")); try { consumer.poll(Collections.singleton(ssp), 0).get(ssp);