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

Weird behaviour when adding jwt-simple to my project #80

Closed
l1x opened this issue Dec 14, 2022 · 2 comments
Closed

Weird behaviour when adding jwt-simple to my project #80

l1x opened this issue Dec 14, 2022 · 2 comments

Comments

@l1x
Copy link

l1x commented Dec 14, 2022

❯ cargo lambda build --release --arm64
   Compiling radmin v0.1.0 (/Users/l1x/code/datadeft/datadeft/backend/radmin)
    Finished release [optimized] target(s) in 8.68s
❯ git diff Cargo.toml
diff --git a/backend/radmin/Cargo.toml b/backend/radmin/Cargo.toml
index f1b5c84..400457c 100644
--- a/backend/radmin/Cargo.toml
+++ b/backend/radmin/Cargo.toml
@@ -8,6 +8,7 @@ async_once = "0.2.6"
 aws-config = "0.51.0"
 aws-sdk-s3 = "0.21.0"
 chrono = "0.4.23"
+jwt-simple = "0.11.2"
 lambda_http = {version = "0.7.1", optional = true}
 lambda_runtime = {version = "0.7.1", optional = true}
 lazy_static = "1.4.0"
❯ cargo lambda build --release --arm64
   Compiling radmin v0.1.0 (/Users/l1x/code/datadeft/datadeft/backend/radmin)
error[E0277]: `*const aws_sdk_s3::Client` cannot be sent between threads safely
  --> src/radmin.rs:23:1
   |
23 | / lazy_static! {
24 | |     static ref S3_CLIENT: AsyncOnce<S3Client> = AsyncOnce::new(async {
25 | |         let region_provider = RegionProviderChain::default_provider().or_else("eu-west-1");
26 | |         let config = aws_config::from_env().region(region_provider).load().await;
...  |
52 | |     };
53 | | }
   | |_^ `*const aws_sdk_s3::Client` cannot be sent between threads safely
   |
   = help: the trait `Send` is not implemented for `*const aws_sdk_s3::Client`
   = note: required for `Cell<*const aws_sdk_s3::Client>` to implement `Send`
   = note: required because it appears within the type `AsyncOnce<aws_sdk_s3::Client>`
   = note: required for `spin::once::Once<AsyncOnce<aws_sdk_s3::Client>>` to implement `Sync`
   = note: required because it appears within the type `Lazy<AsyncOnce<aws_sdk_s3::Client>>`
   = note: shared static variables must have a type that implements `Sync`
   = note: this error originates in the macro `__lazy_static_create` which comes from the expansion of the macro `lazy_static` (in Nightly builds, run with -Z macro-backtrace for more info)
@jedisct1
Copy link
Owner

That seems off-topic.

But usually, in order to work around this error, you need to wrap everything in std::sync::Arc<>, and if that doesn't work, try std::sync::Arc<std::sync::Mutex<>>. If that still doesn't work, make all your structures Clone-able.

@nickpresta
Copy link

For what it's worth, I'm seeing something similar. The act of simply including jwt-simple to my Cargo.toml causes my build to fail (in this case, another crate is failing):

187 | /     lazy_static!{
188 | |         static ref _shared_context_cache: Arc<PredictionContextCache> = Arc::new(PredictionContextCache::new());
189 | |         static ref VOCABULARY: Box<dyn Vocabulary> = Box::new(VocabularyImpl::new(_LITERAL_NAMES.iter(), _SYMBOLIC_NAMES.iter(), None));
190 | |     }
    | |_____^ `(dyn Vocabulary + 'static)` cannot be sent between threads safely
    |
    = help: the trait `Send` is not implemented for `(dyn Vocabulary + 'static)`
    = note: required for `Unique<(dyn Vocabulary + 'static)>` to implement `Send`
    = note: required because it appears within the type `Box<(dyn Vocabulary + 'static)>`
    = note: required for `spin::once::Once<Box<(dyn Vocabulary + 'static)>>` to implement `Sync`
    = note: required because it appears within the type `Lazy<Box<(dyn Vocabulary + 'static)>>`
    = note: shared static variables must have a type that implements `Sync`
    = note: this error originates in the macro `__lazy_static_create` which comes from the expansion of the macro `lazy_static` (in Nightly builds, run with -Z macro-backtrace for more info)

After doing some digging, this actually looks to be an issue with lazy_static:

rust-lang-nursery/lazy-static.rs#204

Specifically, the rsa crate that's included by jwt-simple depends on num-bigint-dig, which depends on lazy_static with the spin_no_std feature, and once that feature is enabled everyone gets it. Here's a related issue: rust-lang-nursery/lazy-static.rs#150

At the end of the day, I ended up forking num-bigint-dig and then patching it in my Cargo.toml:

[patch.crates-io]
num-bigint-dig = { git = "https://github.com/nickpresta/num-bigint.git", branch = "master" }

This now gets the cargo build working again.

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

No branches or pull requests

3 participants