Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concurrent SES and DynamoDB use in Lambda causes Fatal error: Tls Context failed to create. #1077

Closed
mgacy opened this issue Aug 11, 2023 · 5 comments
Assignees
Labels
bug This issue is a bug.

Comments

@mgacy
Copy link

mgacy commented Aug 11, 2023

Describe the bug

Attempting to send an email using AWSSES and put an item with AWSDynamoDB concurrently in an AWS Lambda causes a crash from Fatal error: Tls Context failed to create.

Expected Behavior

The SDK does not crash

Current Behavior

The SDK crashes with the following message from the Lambda's CloudWatch logs:

ClientRuntime/SDKDefaultIO.swift:70: Fatal error: Tls Context failed to create. This should never happen.Please open a
Github issue with us at https://github.com/awslabs/aws-sdk-swift.
RequestId: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Error: Runtime exited with error: signal: trace/breakpoint trap Runtime.ExitError

Reproduction Steps

I have a full example with a SAM template at https://github.com/mgacy/aws-sdk-crash; the function code is:

import AWSDynamoDB
import AWSLambdaEvents
import AWSLambdaRuntime
import AWSSES
import Foundation

@main
struct ExampleLambda: SimpleLambdaHandler {
    func handle(_ event: APIGatewayV2Request, context: LambdaContext) async throws -> APIGatewayV2Response {
        context.logger.info("RECEIVED: \(event)")

        async let putResponse = try await persistItem("us-east-1", tableName: "Test")
        async let emailResponse = try await sendEmail(to: "example@email.com", from: "example@email.com")
        let (putOutput, emailOutput) = try await (putResponse, emailResponse)
        context.logger.info("SAVED: \(putOutput) and SENT: \(emailOutput)")

        return APIGatewayV2Response(statusCode: .ok)
    }
}

extension ExampleLambda {
    func sendEmail(to recipient: String, from sender: String) async throws -> SendEmailOutputResponse {
        let sesClient = try await SESClient()
        let email = SendEmailInput(
            destination: SESClientTypes.Destination(toAddresses: [recipient]),
            message: SESClientTypes.Message(
                body: SESClientTypes.Body(text: SESClientTypes.Content(data: "Test")),
                subject: SESClientTypes.Content(data: "Testing ...")),
            replyToAddresses: nil,
            returnPath: nil,
            source: sender
        )
        return try await sesClient.sendEmail(input: email)
    }

    func persistItem(_ region: String, tableName: String) async throws -> PutItemOutputResponse {
        let dbClient = try DynamoDBClient(region: region)
        let item: [String: DynamoDBClientTypes.AttributeValue] = [
            "CreatedAt": .s(ISO8601DateFormatter().string(from: Date()))
        ]
        return try await dbClient.putItem(input: PutItemInput(
            item: item,
            tableName: tableName))
    }
}

Possible Solution

N/A

Additional Information/Context

The function is using runtime version: provided:al2.v20

AWS SWIFT SDK version used

0.22.0

Compiler and Version used

Swift 5.7

Operating System and version

Built for arm64 using the swift:5.7-amazonlinux2 image

@mgacy mgacy added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 11, 2023
@jbelkins
Copy link
Contributor

Thanks for your report. We'll investigate, and we'll get back to you if we need more info or resolve the problem.

@jbelkins jbelkins added this to the GA milestone Aug 21, 2023
@jbelkins jbelkins removed the needs-triage This issue or PR still needs to be triaged. label Aug 21, 2023
@sichanyoo sichanyoo assigned sichanyoo and unassigned sichanyoo Aug 29, 2023
@sichanyoo
Copy link
Contributor

Error is thrown in aws-crt-swift during TLSContext construction. Needs further investigation from CRT side.

@dayaffe
Copy link
Contributor

dayaffe commented Sep 11, 2023

Being tracked in CRT awslabs/aws-crt-swift#197

@sichanyoo
Copy link
Contributor

@mgacy

We've added a way to change log levels for CRT (one of our dependency which is where the error is being thrown from) as part of 0.35.0 release of aws-sdk-swift. We need trace level logs to determine what the specific issue is.

Could you call this method once at application start to set the CRT log level to .trace and post the entirety of the logs in this thread?

Please delete / censor out any personal information like credentials, etc. from the logs before posting.

@smivij smivij removed this from the GA milestone Apr 17, 2024
@sichanyoo
Copy link
Contributor

Closing this ticket as it has seen no customer interaction and has gone stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

5 participants