---
schema_version: "1"
id: 22eff63857e3f015b0f6e55999664d87afd9ed2aa1dcf265ab11ace5ad8ac455
title: Until Successful Scope
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mule-runtime/4.12/until-successful-scope.md
canonical_url: https://docs.mulesoft.com/mule-runtime/4.12/until-successful-scope
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 702d4c5523c208c193804c1d0ee956be987583672f139743e01d8ce5bfe6d68c
description: MuleSoft Documentation Site
release: "4.12"
latest: false
---
---
product: Mule Runtime
version: 4.12
keywords: anypoint studio, studio, mule, until successful, reattempts, retry
---

# Until Successful Scope

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

The Until Successful scope executes processors within it, in order, until they all succeed or the
scope exhausts the maximum number of retries. Until Successful runs synchronously. If any processor
within the scope fails to connect or to produce a successful result, Until Successful retries all
the processors within it, including the one that failed, until all configured retries are exhausted.
If a retry succeeds, the scope proceeds to the next component. If the final retry doesn’t succeed,
Until Successful produces an error.

Routing is successful if no exception is raised or if the response matches an expression.

Common processes that use Until Successful include:

- Dispatching to outbound endpoints, for example, when calling a remote web service that might have
  availability issues.

- Executing a component method, for example, when executing on a Spring bean that may depend on
  unreliable resources.

- Using a sub-flow to re-execute several actions until they all succeed.

## Until Successful Scope Configuration

To configure an Until Successful scope, add the `<until-successful>` XML element inside an
application flow.

You can configure the following attributes in the Until Successful scope:

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Field</th><th>XML</th><th>Description</th></tr></thead><tbody><tr><td><p>Max Retries</p></td><td><p><code>maxRetries</code></p></td><td><p>Specifies the maximum number of retries that are allowed. This attribute can be either a number or an expression that resolves to a number. An error message looks like this: <code>Message: 'until-successful' retries exhausted.</code> The Mule error type is <code>MULE:RETRY_EXHAUSTED</code>.</p></td></tr><tr><td><p>Milliseconds Between Retries</p></td><td><p><code>millisBetweenRetries</code></p></td><td><p>Specifies the minimum interval, in milliseconds, between retries. The actual interval depends on the duration of the previous attempt, but it shouldn’t exceed twice this value. The default is <code>60000</code> (one minute). This attribute can be either a number or an expression that resolves to a number.</p></td></tr></tbody></table>

## Example Configuration of the Until Successful Scope

The following XML example configures a flow triggered by a Scheduler component and an Until
Successful scope that executes an FTP Write operation:

```xml
<!-- FTP Connector config-->
<ftp:config name="FTP_Config" doc:name="FTP Config" >
  <ftp:connection workingDir="${ftp.dir}" host="${ftp.host}" />
</ftp:config>

<flow name="untilSuccessfulFlow" >
  <!-- Scheduler component to trigger the flow-->
  <scheduler doc:name="Scheduler" >
    <scheduling-strategy >
      <fixed-frequency frequency="15" timeUnit="SECONDS"/>
    </scheduling-strategy>
  </scheduler>
  <!-- Until Successful scope-->
  <until-successful maxRetries="5" doc:name="Until Successful" millisBetweenRetries="3000">
    <!-- FTP Write operation that executes as part of the Until Successful Scope -->
    <ftp:write doc:name="Write" config-ref="FTP_Config" path="/"/>
  </until-successful>
  <logger level="INFO" doc:name="File upload success" message="File upload success"/>
  <!-- Error Handler at flow level-->
  <error-handler>
    <on-error-continue enableNotifications="true" logException="true" doc:name="On Error Continue" type="RETRY_EXHAUSTED">
      <logger level="INFO" doc:name="File upload failed" message="File upload failed"/>
    </on-error-continue>
  </error-handler>
</flow>
```

Behavior of the example application:

- If the FTP Write operation fails

  The Until Successful scope retries the operation every `3000` milliseconds until the operation
  succeeds, with a limit of `5` retries. If the last execution fails, the scope throws a
  `MULE:RETRY_EXHAUSTED` error. Then, the `<on-error-continue>` handles the error and executes the
  Logger with the message: `File upload failed`.

  Before throwing `MULE:RETRY_EXHAUSTED`, Mule also logs each unsuccessful attempt to retry
  execution of the processors on the Mule event, for example:

  ```logs
  ERROR 2022-12-09 17:41:44,910 ... event: cdad31c0-782b-11ed-af21-147ddaaf4f97]
  ...UntilSuccessfulRouter: Retrying execution of event, attempt 1 of 5.
  ...
  ERROR 2022-12-09 17:41:55,079 ... event: cdad31c0-782b-11ed-af21-147ddaaf4f97]
  ...UntilSuccessfulRouter: Retrying execution of event, attempt 5 of 5.
  ```

- If the FTP Write operation executes successfully in any of the attempts

  The next processor after the Until Successful scope executes, in this case, the Logger showing the
  message: `File upload success`.

## Variable Propagation

Every execution of the Until Successful scope starts with the same variables and values present
before the execution of the block. New variables or modifications to already-existing variables
while processing one element aren’t visible in the next execution (in case there is an error). If
the execution finishes correctly, the variables (and payload) are propagated to the rest of the
flow.

## See also

- [How Transactions Affect Scopes and Routers](https://docs.mulesoft.com/mule-runtime/4.12/transaction-management#tx_scopes_routers)
