cognitect-labs / aws-api

AWS, data driven
Apache License 2.0
727 stars 100 forks source link

NoClassDefFoundError when calling KMS Encrypt #210

Closed ChrisLane closed 2 years ago

ChrisLane commented 2 years ago

Thank you for your interest in helping to improve Cognitect's aws-api!

Dependencies

                 [com.cognitect.aws/api "0.8.539"]
                 [com.cognitect.aws/endpoints "1.1.12.192"]
                 [com.cognitect.aws/rds "822.2.1109.0"]
                 [com.cognitect.aws/kms "821.2.1107.0"]
                 [com.cognitect.aws/runtime-sagemaker "822.2.1109.0"]
                 [com.cognitect.aws/s3 "822.2.1109.0"]

Description with failing test case

I'm trying to encrypt a string with a particular KMS key using the following code. I expect to get a success response with the encrypted value but instead I get an exception.

The problem goes away if I add [org.eclipse.jetty/jetty-io "9.4.46.v20220331"] to my dependencies, however, this is not a step that I was expecting to need to take.

(require '[cognitect.aws.client.api :as aws])
(def kms (aws/client {:api :kms}))
(aws/invoke kms {:op :Encrypt
                 :request {:KeyId "1111111-2222-3333-4444-555555555555"
                           :Plaintext (.getBytes "test")}})

Stack traces

{:cognitect.anomalies/category :cognitect.anomalies/fault,
 :cognitect.anomalies/message "org/eclipse/jetty/io/CyclicTimeouts$Expirable",
 :cognitect.http-client/throwable #error{:cause "org.eclipse.jetty.io.CyclicTimeouts$Expirable",
                                         :via [{:type java.lang.NoClassDefFoundError,
                                                :message "org/eclipse/jetty/io/CyclicTimeouts$Expirable",
                                                :at [org.eclipse.jetty.client.http.HttpClientTransportOverHTTP
                                                     newHttpDestination
                                                     "HttpClientTransportOverHTTP.java"
                                                     54]}
                                               {:type java.lang.ClassNotFoundException,
                                                :message "org.eclipse.jetty.io.CyclicTimeouts$Expirable",
                                                :at [java.net.URLClassLoader findClass "URLClassLoader.java" 387]}],
                                         :trace [[java.net.URLClassLoader findClass "URLClassLoader.java" 387]
                                                 [java.lang.ClassLoader loadClass "ClassLoader.java" 418]
                                                 [sun.misc.Launcher$AppClassLoader loadClass "Launcher.java" 352]
                                                 [java.lang.ClassLoader loadClass "ClassLoader.java" 351]
                                                 [org.eclipse.jetty.client.http.HttpClientTransportOverHTTP
                                                  newHttpDestination
                                                  "HttpClientTransportOverHTTP.java"
                                                  54]
                                                 [org.eclipse.jetty.client.HttpClient
                                                  lambda$resolveDestination$0
                                                  "HttpClient.java"
                                                  575]
                                                 [java.util.concurrent.ConcurrentHashMap
                                                  computeIfAbsent
                                                  "ConcurrentHashMap.java"
                                                  1660]
                                                 [org.eclipse.jetty.client.HttpClient
                                                  resolveDestination
                                                  "HttpClient.java"
                                                  573]
                                                 [org.eclipse.jetty.client.HttpClient
                                                  resolveDestination
                                                  "HttpClient.java"
                                                  551]
                                                 [org.eclipse.jetty.client.HttpClient send "HttpClient.java" 599]
                                                 [org.eclipse.jetty.client.HttpRequest sendAsync "HttpRequest.java" 778]
                                                 [org.eclipse.jetty.client.HttpRequest send "HttpRequest.java" 765]
                                                 [cognitect.http_client.Client$fn__31820 invoke "http_client.clj" 242]
                                                 [cognitect.http_client.Client submit_STAR_ "http_client.clj" 226]
                                                 [cognitect.http_client$submit invokeStatic "http_client.clj" 213]
                                                 [cognitect.http_client$submit invoke "http_client.clj" 176]
                                                 [cognitect.aws.http.cognitect$create$reify__31848
                                                  _submit
                                                  "cognitect.clj"
                                                  12]
                                                 [cognitect.aws.http$submit invokeStatic "http.clj" 45]
                                                 [cognitect.aws.http$submit invoke "http.clj" 41]
                                                 [cognitect.aws.client$send_request$fn__17531$state_machine__11923__auto____17558$fn__17560$fn__17574
                                                  invoke
                                                  "client.clj"
                                                  104]
                                                 [cognitect.aws.client$send_request$fn__17531$state_machine__11923__auto____17558$fn__17560
                                                  invoke
                                                  "client.clj"
                                                  96]
                                                 [cognitect.aws.client$send_request$fn__17531$state_machine__11923__auto____17558
                                                  invoke
                                                  "client.clj"
                                                  84]
                                                 [clojure.core.async.impl.ioc_macros$run_state_machine
                                                  invokeStatic
                                                  "ioc_macros.clj"
                                                  973]
                                                 [clojure.core.async.impl.ioc_macros$run_state_machine
                                                  invoke
                                                  "ioc_macros.clj"
                                                  972]
                                                 [clojure.core.async.impl.ioc_macros$run_state_machine_wrapped
                                                  invokeStatic
                                                  "ioc_macros.clj"
                                                  977]
                                                 [clojure.core.async.impl.ioc_macros$run_state_machine_wrapped
                                                  invoke
                                                  "ioc_macros.clj"
                                                  975]
                                                 [cognitect.aws.client$send_request$fn__17531 invoke "client.clj" 84]
                                                 [clojure.lang.AFn run "AFn.java" 22]
                                                 [java.util.concurrent.ThreadPoolExecutor
                                                  runWorker
                                                  "ThreadPoolExecutor.java"
                                                  1149]
                                                 [java.util.concurrent.ThreadPoolExecutor$Worker
                                                  run
                                                  "ThreadPoolExecutor.java"
                                                  624]
                                                 [java.lang.Thread run "Thread.java" 750]]}}
dchelimsky commented 2 years ago

I can't reproduce this. Can you please post the complete classpath? lein classpath if it's a lein project, or clj -Spath for a tools.deps project.

dchelimsky commented 2 years ago

I'm closing this since I can't reproduce it an haven't heard back. @ChrisLane, I'll reopen this if you can help me reproduce the behavior. Thanks!

dchelimsky commented 1 year ago

Hi again! I can't be 100% sure without the classpath you see, but what the error suggests is that you have two incompatible versions of jetty on your classpath. This likelihood is reinforced by that fact that specifying [org.eclipse.jetty/jetty-io "9.4.46.v20220331"] resolves the issue.

A lot of the time, build tools like maven, leiningen, and tools.deps make choices for you in the face of transitive dependency conflicts and they end up working out, but sometimes they don't, at which point it becomes your responsibility to resolve it with explicit requires and/or exclusions. I'll add something to the README about this.

nsadeh commented 4 months ago

I just ran into this and it absolutely drove me up the wall, as I have two projects, one a web app and the other an ingest script, that both have 100% the same AWS setup. The ingest script works, the web app doesn't. It took me an hour to figure out that it was a dependency issue, the whole of which I thought I must be hallucinating, because if I just jack in to the data ingest project, the same call succeeds, and when I try it on the web app, it fails with a cryptic error.