@@ -7,7 +7,9 @@ use anyhow::{anyhow, bail};
7
7
use arc_swap:: ArcSwapOption ;
8
8
use async_compression:: tokio:: write:: { GzipEncoder , ZstdEncoder } ;
9
9
use aws_config:: BehaviorVersion ;
10
- use aws_sdk_s3:: config:: { Credentials , Region , SharedCredentialsProvider } ;
10
+ use aws_sdk_s3:: config:: {
11
+ Credentials , Region , SharedCredentialsProvider , StalledStreamProtectionConfig ,
12
+ } ;
11
13
use aws_sdk_s3:: error:: SdkError ;
12
14
use aws_sdk_s3:: operation:: get_object:: builders:: GetObjectFluentBuilder ;
13
15
use aws_sdk_s3:: operation:: get_object:: GetObjectError ;
@@ -125,6 +127,8 @@ pub struct Options {
125
127
pub skip_snapshot : bool ,
126
128
/// Skip uploading snapshots on shutdown
127
129
pub skip_shutdown_upload : bool ,
130
+ /// Stall protection grace period duration for AWS S3 client
131
+ pub stall_protection_grace_period : std:: time:: Duration ,
128
132
}
129
133
130
134
impl Options {
@@ -145,8 +149,13 @@ impl Options {
145
149
"LIBSQL_BOTTOMLESS_AWS_SECRET_ACCESS_KEY was not set"
146
150
) ) ?;
147
151
let session_token: Option < String > = self . session_token . clone ( ) ;
152
+
153
+ let mut stall_protection = StalledStreamProtectionConfig :: enabled ( ) ;
154
+ stall_protection. set_grace_period ( Some ( self . stall_protection_grace_period ) ) ;
155
+
148
156
let conf = loader
149
157
. behavior_version ( BehaviorVersion :: latest ( ) )
158
+ . stalled_stream_protection ( stall_protection. build ( ) )
150
159
. region ( Region :: new ( region) )
151
160
. credentials_provider ( SharedCredentialsProvider :: new ( Credentials :: new (
152
161
access_key_id,
@@ -245,6 +254,11 @@ impl Options {
245
254
let skip_shutdown_upload =
246
255
env_var_or ( "LIBSQL_BOTTOMLESS_SKIP_SHUTDOWN_UPLOAD" , false ) . parse :: < bool > ( ) ?;
247
256
257
+ let stall_protection_grace_period_sec =
258
+ env_var_or ( "LIBSQL_S3_STALL_PROTECTION_GRACE_PERIOD_SEC" , 20 ) . parse :: < u64 > ( ) ?;
259
+ let stall_protection_grace_period =
260
+ std:: time:: Duration :: from_secs ( stall_protection_grace_period_sec) ;
261
+
248
262
Ok ( Options {
249
263
db_id,
250
264
create_bucket_if_not_exists : true ,
@@ -263,6 +277,7 @@ impl Options {
263
277
s3_max_retries,
264
278
skip_snapshot,
265
279
skip_shutdown_upload,
280
+ stall_protection_grace_period,
266
281
} )
267
282
}
268
283
}
0 commit comments