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

CustomizableSend is not Send, causing issues with spawning a task #892

Closed
declanvk opened this issue Sep 15, 2023 · 5 comments
Closed

CustomizableSend is not Send, causing issues with spawning a task #892

declanvk opened this issue Sep 15, 2023 · 5 comments
Labels
bug This issue is a bug.

Comments

@declanvk
Copy link
Contributor

declanvk commented Sep 15, 2023

Describe the bug

When attempting to tokio::spawn a task that executes a customized AWS DynamoDB SDK request it fails to compile because it says that the CustomizableSend is not Send.

Expected Behavior

I expect the CustomizableSend to be Send, and would be able to be used across the .await point in a tokio::spawn.

Current Behavior

Full cargo check output

    Checking send-issue-repro v0.1.0 (/private/var/folders/l8/_j_c77fj5j7g14l6d65l35lh0000gr/T/tmp.sYoWgUf1/send-issue-repro)
error: future cannot be sent between threads safely
   --> src/main.rs:11:31
    |
11  |       let task_1 = tokio::spawn({
    |  _______________________________^
12  | |         let client = Arc::clone(&client);
13  | |         get_and_print_item(client, "Builder", "Bob")
14  | |     });
    | |_____^ future returned by `get_and_print_item` is not `Send`
    |
    = help: the trait `Send` is not implemented for `(dyn customize::internal::CustomizableSend<GetItemOutput, GetItemError, Output = Pin<Box<(dyn Future<Output = Result<GetItemOutput, aws_smithy_http::result::SdkError<GetItemError, http::response::Response<aws_smithy_http::body::SdkBody>>>> + Send + 'static)>>> + 'static)`
note: future is not `Send` as this value is used across an await
   --> src/main.rs:35:61
    |
26  |     let operation = client
    |         --------- has type `CustomizableOperation<GetItemOutput, GetItemError>` which is not `Send`
...
35  |     let item = operation.interceptor(TestInterceptor).send().await?;
    |                                                             ^^^^^^ await occurs here, with `operation` maybe used later
...
40  | }
    | - `operation` is later dropped here
note: required by a bound in `tokio::spawn`
   --> /Users/thedeck/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.32.0/src/task/spawn.rs:166:21
    |
166 |         T: Future + Send + 'static,
    |                     ^^^^ required by this bound in `spawn`
help: use parentheses to call this trait object
    |
14  |     }(/* aws_sdk_dynamodb::config::Builder */));
    |      +++++++++++++++++++++++++++++++++++++++++

error: could not compile `send-issue-repro` due to previous error

I suspect that the suggestion about using parentheses is an issue with rustc diagnostics.

Reproduction Steps

Cargo.toml:

[package]
name = "send-issue-repro"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
aws-sdk-dynamodb = "0.30.0"
aws-config = "0.56.1"
anyhow = "1.0.72"
tokio = { version = "1.29.1", features = ["full", "tracing"] }

src/main.rs:

use std::sync::Arc;

use aws_sdk_dynamodb::{config::Interceptor, types::AttributeValue, Client};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let config = aws_config::load_from_env().await;
    let service_config = aws_sdk_dynamodb::Config::from(&config);
    let client = Arc::new(aws_sdk_dynamodb::Client::from_conf(service_config));

    let task_1 = tokio::spawn({
        let client = Arc::clone(&client);
        get_and_print_item(client, "Builder", "Bob")
    });

    task_1.await??;

    Ok(())
}

async fn get_and_print_item(
    client: Arc<Client>,
    partition_key: &'static str,
    sort_key: &'static str,
) -> anyhow::Result<()> {
    let operation = client
        .get_item()
        .table_name("TestTable")
        .key("PartitionKey", AttributeValue::S(partition_key.into()))
        .key("SortKey", AttributeValue::S(sort_key.into()))
        .projection_expression("PartitionKey, SortKey, Age")
        .customize()
        .await?;

    let item = operation.interceptor(TestInterceptor).send().await?;

    println!("{:?}", item.item.unwrap());

    Ok(())
}

#[derive(Debug)]
pub struct TestInterceptor;

impl Interceptor for TestInterceptor {
    fn name(&self) -> &'static str {
        "tagging-interceptor"
    }
}

Possible Solution

No response

Additional Information/Context

No response

Version

├── aws-config v0.56.1
│   ├── aws-credential-types v0.56.1
│   │   ├── aws-smithy-async v0.56.1
│   │   ├── aws-smithy-types v0.56.1
│   ├── aws-http v0.56.1
│   │   ├── aws-credential-types v0.56.1 (*)
│   │   ├── aws-smithy-http v0.56.1
│   │   │   ├── aws-smithy-types v0.56.1 (*)
│   │   ├── aws-smithy-types v0.56.1 (*)
│   │   ├── aws-types v0.56.1
│   │   │   ├── aws-credential-types v0.56.1 (*)
│   │   │   ├── aws-smithy-async v0.56.1 (*)
│   │   │   ├── aws-smithy-client v0.56.1
│   │   │   │   ├── aws-smithy-async v0.56.1 (*)
│   │   │   │   ├── aws-smithy-http v0.56.1 (*)
│   │   │   │   ├── aws-smithy-http-tower v0.56.1
│   │   │   │   │   ├── aws-smithy-http v0.56.1 (*)
│   │   │   │   │   ├── aws-smithy-types v0.56.1 (*)
│   │   │   │   ├── aws-smithy-types v0.56.1 (*)
│   │   │   ├── aws-smithy-http v0.56.1 (*)
│   │   │   ├── aws-smithy-types v0.56.1 (*)
│   ├── aws-sdk-sso v0.30.0
│   │   ├── aws-credential-types v0.56.1 (*)
│   │   ├── aws-http v0.56.1 (*)
│   │   ├── aws-runtime v0.56.1
│   │   │   ├── aws-credential-types v0.56.1 (*)
│   │   │   ├── aws-http v0.56.1 (*)
│   │   │   ├── aws-sigv4 v0.56.1
│   │   │   │   ├── aws-smithy-http v0.56.1 (*)
│   │   │   ├── aws-smithy-async v0.56.1 (*)
│   │   │   ├── aws-smithy-http v0.56.1 (*)
│   │   │   ├── aws-smithy-runtime-api v0.56.1
│   │   │   │   ├── aws-smithy-async v0.56.1 (*)
│   │   │   │   ├── aws-smithy-http v0.56.1 (*)
│   │   │   │   ├── aws-smithy-types v0.56.1 (*)
│   │   │   ├── aws-smithy-types v0.56.1 (*)
│   │   │   ├── aws-types v0.56.1 (*)
│   │   ├── aws-smithy-async v0.56.1 (*)
│   │   ├── aws-smithy-client v0.56.1 (*)
│   │   ├── aws-smithy-http v0.56.1 (*)
│   │   ├── aws-smithy-json v0.56.1
│   │   │   └── aws-smithy-types v0.56.1 (*)
│   │   ├── aws-smithy-runtime v0.56.1
│   │   │   ├── aws-smithy-async v0.56.1 (*)
│   │   │   ├── aws-smithy-client v0.56.1 (*)
│   │   │   ├── aws-smithy-http v0.56.1 (*)
│   │   │   ├── aws-smithy-runtime-api v0.56.1 (*)
│   │   │   ├── aws-smithy-types v0.56.1 (*)
│   │   ├── aws-smithy-runtime-api v0.56.1 (*)
│   │   ├── aws-smithy-types v0.56.1 (*)
│   │   ├── aws-types v0.56.1 (*)
│   ├── aws-sdk-sts v0.30.0
│   │   ├── aws-credential-types v0.56.1 (*)
│   │   ├── aws-http v0.56.1 (*)
│   │   ├── aws-runtime v0.56.1 (*)
│   │   ├── aws-smithy-async v0.56.1 (*)
│   │   ├── aws-smithy-client v0.56.1 (*)
│   │   ├── aws-smithy-http v0.56.1 (*)
│   │   ├── aws-smithy-json v0.56.1 (*)
│   │   ├── aws-smithy-query v0.56.1
│   │   │   ├── aws-smithy-types v0.56.1 (*)
│   │   ├── aws-smithy-runtime v0.56.1 (*)
│   │   ├── aws-smithy-runtime-api v0.56.1 (*)
│   │   ├── aws-smithy-types v0.56.1 (*)
│   │   ├── aws-smithy-xml v0.56.1
│   │   ├── aws-types v0.56.1 (*)
│   ├── aws-smithy-async v0.56.1 (*)
│   ├── aws-smithy-client v0.56.1 (*)
│   ├── aws-smithy-http v0.56.1 (*)
│   ├── aws-smithy-http-tower v0.56.1 (*)
│   ├── aws-smithy-json v0.56.1 (*)
│   ├── aws-smithy-types v0.56.1 (*)
│   ├── aws-types v0.56.1 (*)
├── aws-sdk-dynamodb v0.30.0
│   ├── aws-credential-types v0.56.1 (*)
│   ├── aws-http v0.56.1 (*)
│   ├── aws-runtime v0.56.1 (*)
│   ├── aws-smithy-async v0.56.1 (*)
│   ├── aws-smithy-client v0.56.1 (*)
│   ├── aws-smithy-http v0.56.1 (*)
│   ├── aws-smithy-json v0.56.1 (*)
│   ├── aws-smithy-runtime v0.56.1 (*)
│   ├── aws-smithy-runtime-api v0.56.1 (*)
│   ├── aws-smithy-types v0.56.1 (*)
│   ├── aws-types v0.56.1 (*)


### Environment details (OS name and version, etc.)

macOS Ventura 13.5.2 | cargo 1.69.0 (6e9a83356 2023-04-12) | stable-aarch64-apple-darwin rustc 1.69.0 (84c898d65 2023-04-16)

### Logs

_No response_
```[tasklist]
### Tasks
@declanvk declanvk added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 15, 2023
@declanvk
Copy link
Contributor Author

Looks like this is a duplicate of smithy-lang/smithy-rs#2944 and fixed by smithy-lang/smithy-rs@cf95f48.

I'm not sure why I'm still seeing the issue, let me check the changelog

@ysaito1001 ysaito1001 added the pending-release This issue will be fixed by an approved PR that hasn't been released yet. label Sep 15, 2023
@rcoh
Copy link
Contributor

rcoh commented Sep 18, 2023

it hasn't been released into an SDK yet, we'll do that soon.

@rcoh rcoh removed the needs-triage This issue or PR still needs to be triaged. label Sep 18, 2023
@rcoh
Copy link
Contributor

rcoh commented Sep 20, 2023

fixed

@rcoh rcoh closed this as completed Sep 20, 2023
@github-actions
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.

@rcoh
Copy link
Contributor

rcoh commented Nov 7, 2023

Fix verified.

@rcoh rcoh removed the pending-release This issue will be fixed by an approved PR that hasn't been released yet. label Nov 7, 2023
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

3 participants