You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Add automatic retry support with exponential backoff for FTP client and listener operations](https://github.com/ballerina-platform/ballerina-library/issues/8585)
@@ -161,7 +161,6 @@ public type Error distinct error;
161
161
162
162
*`ConnectionError` - Represents errors that occur when connecting to the FTP/SFTP server. This includes network failures, host unreachable, connection refused, etc.
163
163
```ballerina
164
-
# Represents an error that occurs when connecting to the FTP/SFTP server.
165
164
public type ConnectionError distinct Error;
166
165
```
167
166
@@ -180,55 +179,19 @@ public type FileAlreadyExistsError distinct Error;
180
179
public type InvalidConfigurationError distinct Error;
181
180
```
182
181
183
-
*`ServiceUnavailableError` - Represents errors that occur when the FTP/SFTP service is temporarily unavailable. This is a transient error indicating the operation may succeed on retry. Common causes include server overload (FTP code 421), connection issues (425, 426), temporary file locks (450), or server-side processing errors (451). This error type is designed for use with retry and circuit breaker patterns.
182
+
*`ServiceUnavailableError` - Represents errors that occur when the FTP/SFTP service is temporarily unavailable. This is a transient error indicating the operation may succeed on retry. Common causes include server overload (FTP code 421), connection issues (425, 426), temporary file locks (450), or server-side processing errors (451).
184
183
```ballerina
185
184
public type ServiceUnavailableError distinct Error;
186
185
```
187
186
188
-
All specific error types are subtypes of the base `Error` type, allowing for both specific and general error handling:
189
-
```ballerina
190
-
// Handle specific error types
191
-
ftp:Client|ftp:Error result = new(config);
192
-
if result is ftp:ConnectionError {
193
-
// Handle connection failures specifically
194
-
} else if result is ftp:ServiceUnavailableError {
195
-
// Transient error - retry the operation
196
-
} else if result is ftp:Error {
197
-
// Handle any other FTP error
198
-
}
199
-
```
200
-
### 2.3. Error Types
201
-
The FTP module provides a hierarchy of error types for better error handling and more precise error identification.
202
-
203
-
*`Error` - The base error type for all FTP-related errors.
204
-
```ballerina
205
-
public type Error distinct error;
206
-
```
207
-
208
-
*`ConnectionError` - Represents errors that occur when connecting to the FTP/SFTP server. This includes network failures, host unreachable, connection refused, etc.
209
-
```ballerina
210
-
# Represents an error that occurs when connecting to the FTP/SFTP server.
211
-
public type ConnectionError distinct Error;
212
-
```
213
-
214
-
*`FileNotFoundError` - Represents errors that occur when a requested file or directory is not found on the remote server.
215
-
```ballerina
216
-
public type FileNotFoundError distinct Error;
217
-
```
218
-
219
-
*`FileAlreadyExistsError` - Represents errors that occur when attempting to create a file or directory that already exists.
187
+
*`AllRetryAttemptsFailedError` - Represents an error that occurs when all retry attempts have been exhausted. This error wraps the last failure encountered during retry attempts.
220
188
```ballerina
221
-
public type FileAlreadyExistsError distinct Error;
222
-
```
223
-
224
-
*`InvalidConfigurationError` - Represents errors that occur when FTP/SFTP configuration is invalid (e.g., invalid port numbers, invalid regex patterns, invalid timeout values).
225
-
```ballerina
226
-
public type InvalidConfigurationError distinct Error;
189
+
public type AllRetryAttemptsFailedError distinct Error;
227
190
```
228
191
229
-
*`ServiceUnavailableError` - Represents errors that occur when the FTP/SFTP service is temporarily unavailable. This is a transient error indicating the operation may succeed on retry. Common causes include server overload (FTP code 421), connection issues (425, 426), temporary file locks (450), or server-side processing errors (451). This error type is designed for use with retry and circuit breaker patterns.
192
+
*`CircuitBreakerOpenError` - Error returned when the circuit breaker is in OPEN state. This indicates the FTP server is unavailable and requests are being blocked to prevent cascade failures. This is a subtype of `ServiceUnavailableError`.
230
193
```ballerina
231
-
public type ServiceUnavailableError distinct Error;
194
+
public type CircuitBreakerOpenError distinct ServiceUnavailableError;
232
195
```
233
196
234
197
All specific error types are subtypes of the base `Error` type, allowing for both specific and general error handling:
@@ -237,6 +200,10 @@ All specific error types are subtypes of the base `Error` type, allowing for bot
237
200
ftp:Client|ftp:Error result = new(config);
238
201
if result is ftp:ConnectionError {
239
202
// Handle connection failures specifically
203
+
} else if result is ftp:CircuitBreakerOpenError {
204
+
// Circuit breaker is open - implement fallback logic
205
+
} else if result is ftp:AllRetryAttemptsFailedError {
206
+
// All retries exhausted - consider alerting
240
207
} else if result is ftp:ServiceUnavailableError {
241
208
// Transient error - retry the operation
242
209
} else if result is ftp:Error {
@@ -284,6 +251,8 @@ public type ClientConfiguration record {|
284
251
boolean laxDataBinding = false;
285
252
# Retry configuration for read operations
286
253
RetryConfig retryConfig?;
254
+
# Circuit breaker configuration to prevent cascade failures
255
+
CircuitBreakerConfig circuitBreaker?;
287
256
|};
288
257
```
289
258
* InputContent record represents the configurations for the input given for `put` and `append` operations.
@@ -319,8 +288,84 @@ public enum FileWriteOption {
319
288
APPEND
320
289
}
321
290
```
322
-
### 3.2. Initialization
323
-
#### 3.2.1. Insecure Client
291
+
### 3.2. Circuit Breaker
292
+
The circuit breaker pattern prevents cascade failures by temporarily blocking requests to an FTP server experiencing issues. When failures reach a threshold, the circuit "opens" and subsequent requests fail fast with `CircuitBreakerOpenError` without attempting the actual operation.
293
+
294
+
#### State Machine
295
+
The circuit breaker operates in three states:
296
+
-**CLOSED**: Normal operation. Requests are allowed and failures are tracked.
297
+
-**OPEN**: Circuit is tripped. All requests are rejected immediately with `CircuitBreakerOpenError`.
298
+
-**HALF_OPEN**: After the reset time elapses, one trial request is allowed. Success returns to CLOSED; failure returns to OPEN.
299
+
300
+
#### Configuration
301
+
* CircuitBreakerConfig record contains the circuit breaker settings.
302
+
```ballerina
303
+
public type CircuitBreakerConfig record {|
304
+
# Rolling window configuration for failure tracking
305
+
RollingWindow rollingWindow = {};
306
+
# Failure ratio threshold (0.0 to 1.0) that trips the circuit
307
+
float failureThreshold = 0.5;
308
+
# Time in seconds to wait before transitioning from OPEN to HALF_OPEN
309
+
decimal resetTime = 30;
310
+
# Categories of failures that count towards tripping the circuit
0 commit comments