clojure-emacs / cider

The Clojure Interactive Development Environment that Rocks for Emacs
https://cider.mx
GNU General Public License v3.0
3.55k stars 645 forks source link

Strange bug with clj-http #2214

Closed yogsototh closed 6 years ago

yogsototh commented 6 years ago

Expected behavior

Launching the tests using clj-http call.

(client/post "http://localhost:3456/token"
                    {:form-params req
                       :headers {:Authorization (str "Bearer " jwt)}
                       :throw-exceptions? false})

Should return a body.

Actual behavior

When the code is run with lein test or in a lein repl it works as expected. But inside cider. I get this error:

resumed as: javax.servlet.http.HttpServletRequest.isAsyncStarted()Z

Full stack trace:

1. Unhandled clojure.lang.ExceptionInfo
   clj-http: status 500
   {:request-time 80,
    :repeatable? false,
    :protocol-version {:name "HTTP", :major 1, :minor 1},
    :streaming? true,
    :chunked? false,
    :type :clj-http.client/unexceptional-status,
    :reason-phrase
    "javax.servlet.http.HttpServletRequest.isAsyncStarted()Z",
    :headers
    {"Date" "Thu, 22 Feb 2018 10:09:47 GMT",
     "Content-Security-Policy"
     "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; connect-src 'self'; form-action 'none'; frame-ancestor 'none'; plugin-types 'none';",
     "X-Frame-Options" "DENY",
     "Cache-Control" "must-revalidate,no-cache,no-store",
     "Content-Type" "text/html; charset=ISO-8859-1",
     "Content-Length" "340",
     "Connection" "close",
     "Server" "Jetty(9.2.10.v20150310)"},
    :orig-content-encoding nil,
    :status 500,
    :length 340,
    :body
    "<html>\n<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html;charset=ISO-8859-1\"/>\n<title>Error 500 </title>\n</head>\n<body>\n<h2>HTTP ERROR: 500</h2>\n<p>Problem accessing /oauth2/authorize. Reason:\n<pre>    javax.servlet.http.HttpServletRequest.isAsyncStarted()Z</pre></p>\n<hr /><i><small>Powered by Jetty://</small></i>\n</body>\n</html>\n",
    :trace-redirects []}

               support.clj:  201  slingshot.support/stack-trace
                client.clj:  239  clj-http.client/exceptions-response
                client.clj:  230  clj-http.client/exceptions-response
                client.clj:  248  clj-http.client/wrap-exceptions/fn
                client.clj:  724  clj-http.client/wrap-accept/fn
                client.clj:  746  clj-http.client/wrap-accept-encoding/fn
                client.clj:  707  clj-http.client/wrap-content-type/fn
                client.clj:  948  clj-http.client/wrap-form-params/fn
                client.clj:  983  clj-http.client/wrap-nested-params/fn
                client.clj:  882  clj-http.client/wrap-method/fn
               cookies.clj:  131  clj-http.cookies/wrap-cookies/fn
                 links.clj:   63  clj-http.links/wrap-links/fn
                client.clj: 1009  clj-http.client/wrap-unknown-host/fn
                client.clj: 1181  clj-http.client/request*
                client.clj: 1174  clj-http.client/request*
                client.clj: 1199  clj-http.client/post
                client.clj: 1195  clj-http.client/post
               RestFn.java:  423  clojure.lang.RestFn/invoke
oauth2_web_service_test.clj:  130  iroh-auth.oauth2-web-service-test/post-authorize
....

Steps to reproduce the problem

I think simply creating a compojure-api route accepting form-params and running the call should be enough.

(POST "/token" req
          :form-params [ client_id :- s/Str
                                     scope     :- s/Str ]
              (resp/ok {:data "it works!"}))

Environment & Version information

I use spacemacs (development branch) 0.300.0@25.3.1 on MacOS.

Here is the message I get when I make a jack-in:

Starting nREPL server via /usr/local/bin/lein update-in :dependencies conj \[org.clojure/tools.nrepl\ \"0.2.13\"\ \:exclusions\ \[org.clojure/clojure\]\] -- update-in :plugins conj \[com.billpiel/sayid\ \"0.0.15\"\] -- update-in :plugins conj \[refactor-nrepl\ \"2.4.0-SNAPSHOT\"\] -- update-in :plugins conj \[cider/cider-nrepl\ \"0.17.0-SNAPSHOT\"\] -- repl :headless :host ::...

CIDER version information

Include here the version string displayed when CIDER's REPL is launched. Here's an example:

CIDER 0.17.0snapshot (package: 20171228.1254), nREPL 0.2.12
Clojure 1.8.0, Java 1.8.0_77

Emacs version

25.3.1

Operating system

macOS X High Sierra 10.13.3 (17D47)

yogsototh commented 6 years ago

Follow up, I've upgraded all my dependencies, in particular clj-http one and it works as expected. Still that behaviour was strange as there was a clear difference between the behaviour in the REPL and in Cider

bbatsov commented 6 years ago

I'm curious whether you would have gotten the same problem if you started lein repl the same way CIDER starts it. Generally there should be no difference between evaluating stuff in CIDER and lein repl.

xiongtx commented 6 years ago

Since this has been resolved by upgrading, it can be 📕. Feel free to post more info if you find it.