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

SDK calls do not propagate coroutine context #1384

Closed
cloudshiftchris opened this issue Aug 16, 2024 · 2 comments
Closed

SDK calls do not propagate coroutine context #1384

cloudshiftchris opened this issue Aug 16, 2024 · 2 comments
Labels
bug This issue is a bug. needs-triage This issue or PR still needs to be triaged.

Comments

@cloudshiftchris
Copy link

cloudshiftchris commented Aug 16, 2024

Describe the bug

Our SaaS software is multi-tenant - at the start of each request we identify/validate the tenant and add that to the coroutine context, such that the tenant is available downstream.

The coroutine-scoped tenant context used for various low-level tasks - in this case, we also have scoped-down IAM policies; calls to SDK functions go through a credentials provider that will dynamically scope down policies. For example, an S3 policy would be scoped down to only allow "/tenant-id/*", ditto for dynamo, etc.

That all works fine (and has for quite a while). When we use constructs such as the below - SDK call returning a Flow that invokes other SDK calls (the fact that these are dynamo calls isn't material) - the outer call works fine (scoped down policy applied, call is executed), but the inner call fails in the credentials provider as it can't resolve the tenant.

dynamoDb
    .queryPaginated {
        tableName = gatewayTable.value
        keyConditionExpression = "#tenantId = :tenantId"
        expressionAttributeNames =
            mapOf(
                "#tenantId" to GatewayPrimaryKey.partitionKeyName,
                "#gatewayId" to GatewayPrimaryKey.sortKeyName)
        expressionAttributeValues = mapOf(":tenantId" to AttributeValue.S(tenant.id.value))
        projectionExpression = "#tenantId, #gatewayId"
    }
    .collect {
        it.items
            .orEmpty()
            .asSequence()
            .map { WriteRequest { deleteRequest { key = it } } }
            .chunked(25)
            .forEach { deleteRequests ->
                dynamoDb.batchWriteItem {
                    requestItems = mapOf(gatewayTable.value to deleteRequests)
                }
            }
    }

Expected behavior

Elements added to the coroutine context are propagated to coroutines created by the SDK.

Current behavior

Coroutine context is not propagated.

Steps to Reproduce

no reproducer available atm; lmk if the overall context is insufficient to identify the issue.

Possible Solution

when launching coroutines inside the SDK propagate context elements.

Context

Unable to use the SDK in situations where there are nested SDK calls.

A possible workaround, with material performance/scalability impacts, is to avoid the nested calls - load all the outer data, then process it (bulk processing vs streaming of results).

AWS SDK for Kotlin version

1.3.x

Platform (JVM/JS/Native)

JVM

Operating system and version

macOS Sonoma / Windows / Linux (all affected)

@cloudshiftchris cloudshiftchris added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 16, 2024
@cloudshiftchris
Copy link
Author

Closing this - false positive, there were other components that had negative interactions.

Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

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. needs-triage This issue or PR still needs to be triaged.
Projects
None yet
Development

No branches or pull requests

1 participant