Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The `aws_s3` source now logs an error containing the S3 object key whenever it fails to process an S3 event (e.g. a `GetObject` failure, a decode error, or a downstream acknowledgement error), making it easier to identify which object failed without cross-referencing SQS message IDs.
3 changes: 3 additions & 0 deletions changelog.d/aws_s3_source_s3_timeouts.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The `aws_s3` source now bounds its S3 `GetObject` requests with default client timeouts (`connect_timeout_seconds = 5`, `read_timeout_seconds = 30`) and exposes them as configuration options. Previously the S3 client was created without a read or operation timeout, so a half-open or silently dropped connection — for example one reaped by a NAT gateway idle timeout — could hang a polling task indefinitely, stalling SQS-based S3 ingestion until the process was restarted. The `read_timeout` applies per-read, so slow but steadily progressing transfers of large objects are not cut off. Any dimension can be overridden (or an operation timeout added) via `connect_timeout_seconds`, `read_timeout_seconds`, and `operation_timeout_seconds` on the source.

authors: taylorchandleryoung
15 changes: 15 additions & 0 deletions src/aws/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ pub struct AwsTimeout {
}

impl AwsTimeout {
/// Creates a new timeout configuration from the given connect, operation, and read
/// timeouts, each expressed in seconds. A `None` leaves that dimension unbounded (subject
/// to the AWS SDK defaults).
pub const fn new(
connect_timeout: Option<u64>,
operation_timeout: Option<u64>,
read_timeout: Option<u64>,
) -> Self {
Self {
connect_timeout,
operation_timeout,
read_timeout,
}
}

/// returns the connection timeout
pub const fn connect_timeout(&self) -> Option<u64> {
self.connect_timeout
Expand Down
51 changes: 49 additions & 2 deletions src/sources/aws_s3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ use vrl::value::{Kind, kind::Collection};

use super::util::MultilineConfig;
use crate::{
aws::{RegionOrEndpoint, auth::AwsAuthentication, create_client, create_client_and_region},
aws::{
AwsTimeout, RegionOrEndpoint, auth::AwsAuthentication, create_client,
create_client_and_region,
},
codecs::DecodingConfig,
common::{s3::S3ClientBuilder, sqs::SqsClientBuilder},
config::{
Expand Down Expand Up @@ -117,6 +120,19 @@ pub struct AwsS3Config {
#[configurable(derived)]
tls_options: Option<TlsConfig>,

/// Client timeout configuration for S3 operations.
///
/// These settings bound the S3 `GetObject` request and the read of its response body. Any
/// dimension left unset falls back to a safe default (`connect_timeout_seconds = 5`,
/// `read_timeout_seconds = 30`) so that a half-open or silently dropped connection — for
/// example one reaped by a NAT gateway idle timeout — cannot hang a polling task
/// indefinitely and stall S3 ingestion. `read_timeout_seconds` applies per-read rather than
/// to the whole request, so a slow but steadily progressing transfer of a large object is
/// not cut off.
#[configurable(derived)]
#[serde(default)]
timeout: Option<AwsTimeout>,

/// The namespace to use for logs. This overrides the global setting.
#[configurable(metadata(docs::hidden))]
#[serde(default)]
Expand Down Expand Up @@ -151,6 +167,33 @@ const fn default_true() -> bool {
true
}

/// Default connect timeout for the S3 client, in seconds.
const DEFAULT_S3_CONNECT_TIMEOUT_SECONDS: u64 = 5;

/// Default read (per-read inactivity) timeout for the S3 client, in seconds.
///
/// This bounds the response-body read of `GetObject` so a stalled or silently dropped
/// connection cannot hang a polling task indefinitely. It is applied per-read, so a slow but
/// steadily progressing transfer of a large object is not cut off. No operation timeout is set
/// by default, to avoid capping legitimately long large-object transfers.
const DEFAULT_S3_READ_TIMEOUT_SECONDS: u64 = 30;

/// Resolves the effective S3 client timeout, applying default bounds to any dimension the
/// configuration leaves unset. Connect and read timeouts default to bounded values; the
/// operation timeout is left unset so large-object transfers are not capped.
fn resolve_s3_timeout(configured: Option<AwsTimeout>) -> AwsTimeout {
let configured = configured.unwrap_or_default();
AwsTimeout::new(
configured
.connect_timeout()
.or(Some(DEFAULT_S3_CONNECT_TIMEOUT_SECONDS)),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question is this default value how the code behaved previously? If not then maybe we would consider doing nothing if the optional is not filled. Many other integrations do this instead of falling back to a hardcoded default.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the default value before was 3.1 seconds https://github.com/awslabs/aws-sdk-rust/blob/33a43d1891b5ae5f5c3ed83343193967c7e01446/sdk/aws-smithy-runtime/src/client/defaults.rs#L38 now we're setting it to 5 seconds. Read timeout wasn't set at all so we're setting it to 30seconds which I think is a good default, cause if the connection is stuck, i.e we've connected but no data is coming across then we shouldn't hang indefinitely.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm i see. This can go down two paths either:

  1. we are ok with whatever default the provider ships in their library
  2. we are not ok and we think 5s is a better choice.

If we go with (1) then my previous suggestion works. If (2) then I think the conventional way to do this in vector is with the #[serde(default) = "xyz"] configurable component tag.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright made a larger update, looks like a lot but it's all kinda samey, decided to add timeouts to all the other AWS integrations as well.

configured.operation_timeout(),
configured
.read_timeout()
.or(Some(DEFAULT_S3_READ_TIMEOUT_SECONDS)),
Comment thread
petere-datadog marked this conversation as resolved.
Outdated
Comment thread
petere-datadog marked this conversation as resolved.
Outdated
)
}

impl_generate_config_from_default!(AwsS3Config);

#[async_trait::async_trait]
Expand Down Expand Up @@ -243,6 +286,10 @@ impl AwsS3Config {
let region = self.region.region();
let endpoint = self.region.endpoint();

// Bound the S3 client's requests. Historically this was `None`, which left the
// response-body read of `GetObject` unbounded, so a half-open or silently dropped
// connection could hang a polling task indefinitely and stall SQS-based ingestion.
let s3_timeout = resolve_s3_timeout(self.timeout);
let s3_client = create_client::<S3ClientBuilder>(
&S3ClientBuilder {
force_path_style: Some(self.force_path_style),
Expand All @@ -252,7 +299,7 @@ impl AwsS3Config {
endpoint.clone(),
proxy,
self.tls_options.as_ref(),
None,
Some(&s3_timeout),
)
.await?;

Expand Down
22 changes: 22 additions & 0 deletions src/sources/aws_s3/sqs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,23 @@ pub enum ProcessingError {
},
}

impl ProcessingError {
/// Returns the S3 object key associated with this error, if the failure occurred after the
/// S3 event record (and thus its key) was known.
fn key(&self) -> Option<&str> {
match self {
ProcessingError::GetObject { key, .. }
| ProcessingError::ReadObject { key, .. }
| ProcessingError::PipelineSend { key, .. }
| ProcessingError::WrongRegion { key, .. }
| ProcessingError::ErrorAcknowledgement { key, .. }
| ProcessingError::FileTooOld { key, .. } => Some(key),
ProcessingError::InvalidSqsMessage { .. }
| ProcessingError::UnsupportedS3EventVersion { .. } => None,
}
}
}

pub struct State {
region: Region,

Expand Down Expand Up @@ -524,6 +541,11 @@ impl IngestorProcess {
}
}
_ => {
error!(
message = "Failed to process S3 event.",
key = err.key().unwrap_or("<unknown>"),
error = %err,
);
emit!(SqsMessageProcessingError {
message_id: &message_id,
error: &err,
Expand Down
Loading