diff --git a/src/aws/flb_aws_credentials_ec2.c b/src/aws/flb_aws_credentials_ec2.c index 688d143f2d2..ff1a1237840 100644 --- a/src/aws/flb_aws_credentials_ec2.c +++ b/src/aws/flb_aws_credentials_ec2.c @@ -176,7 +176,17 @@ void upstream_set_fn_ec2(struct flb_aws_provider *provider, flb_debug("[aws_credentials] upstream_set called on the EC2 provider"); /* Make sure TLS is set to false before setting upstream, then reset it */ ins->use_tls = FLB_FALSE; + + /* IMDSv2 token request will timeout if hops = 1 and running within container */ + ins->io_timeout = FLB_AWS_IMDS_TIMEOUT; + ins->keepalive = FLB_FALSE; /* On timeout, the connection is broken */ + flb_output_upstream_set(implementation->client->upstream, ins); + + /* Reset */ + ins->keepalive = FLB_TRUE; + ins->io_timeout = 0; + ins->use_tls = FLB_TRUE; }