Problem in production when removing wrap-reload

37 views
Skip to first unread message

Andros Fenollosa

unread,
Apr 26, 2020, 11:22:42 AM4/26/20
to Compojure
I'm setting up a service that returns a JSON. The problem I have is when I want to use Nginx as a reverse proxy. If I use the following handlers it doesn't work.


    (def wrapped-handler
     
;; Handler middlewares
     
(-> all-routes
         
(wrap-defaults (assoc-in site-defaults [:security :anti-forgery] false))
          wrap
-params
          wrap
-session
         
))



The message I get back is

    java.lang.NullPointerException
            at ring
.adapter.jetty$proxy_handler$fn__6990.invoke(jetty.clj:26)
            at ring
.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle(Unknown Source)
            at org
.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
            at org
.eclipse.jetty.server.Server.handle(Server.java:503)
            at org
.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364)
            at org
.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
            at org
.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
            at org
.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
            at org
.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
            at org
.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
            at org
.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
            at java
.base/java.lang.Thread.run(Thread.java:834)




But if I add wrap-reload everything goes right.

    (def wrapped-handler
     
;; Handler middlewares
     
(-> all-routes
         
(wrap-defaults (assoc-in site-defaults [:security :anti-forgery] false))
          wrap
-params
          wrap
-session
          wrap
-reload
         
))



My setup with Nginx is as follows.

    server
{        
   
            server_name domain
.com;
   
            location
/ {
                proxy_pass http
://localhost:9000/;
                proxy_set_header
Host $http_host;
                proxy_set_header X
-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X
-Forwarded-Proto $scheme;
                proxy_redirect  off
;
           
}
   
}


Is it safe to leave wrap-reload in production?
What have I left behind?

Thank you all in advance.

James Reeves

unread,
Apr 26, 2020, 12:34:08 PM4/26/20
to Compojure
The first problem that stands out is that you're applying your middleware twice. The wrap-defaults middleware includes wrap-params and wrap-session, and applying them again you're going to run into problems.

You haven't mentioned what version of Ring you're having problems with. The stack trace suggests you're not using the latest stable version of the Jetty adapter, so maybe try updating to 1.8.0 to start.

Your error is an odd one - my guess is that it's a dependency or class file issue, so you should check your dependency tree ("lein deps :tree" if you're using Leiningen), and clean your target directory (lein clean).

--
You received this message because you are subscribed to the Google Groups "Compojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to compojure+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/compojure/ab2041d1-c31a-4d31-91e1-0a70a6d70cbc%40googlegroups.com.


--
James Reeves
Message has been deleted

Andros Fenollosa

unread,
Apr 28, 2020, 5:17:15 PM4/28/20
to Compojure
Before we continue, I would like to thank you very much for your explanation.

I have continued the steps
, now I am using the latest version of Ring, I have cleaned with lein clean , I have eliminated the extra headers... but the problem persists... I'm quite confused about it, I feel stuck.

java.lang.NullPointerException
        at ring.adapter.jetty$proxy_handler$fn__6280.invoke(jetty.clj:27)
        at ring.adapter.jetty.proxy$org.eclipse.jetty.server.handler.AbstractHandler$ff19274a.handle(Unknown Source)
        at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
        at org.eclipse.jetty.server.Server.handle(Server.java:500)
        at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:386)
        at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:562)
        at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:378)
        at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:270)
        at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
        at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
        at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:117)
        at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)
        at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)
        at java.base/java.lang.Thread.run(Thread.java:834)


My core

(ns glosa.core
 
(:require
   
[glosa.config :refer [config]]
   
[ring.middleware.defaults :refer [site-defaults wrap-defaults]]
   
[ring.middleware.reload :refer [wrap-reload]]
   
[ring.middleware.cors :refer [wrap-cors]]
   
[glosa.urls :refer [all-routes]]
   
[ring.adapter.jetty :refer [run-jetty]]) (:gen-class))


(def wrapped-handler
 
;; Handler middlewares
 
(-> all-routes
     
(wrap-defaults (assoc-in site-defaults [:security :anti-forgery] false))

     
(wrap-cors
       
:access-control-allow-origin [(re-pattern (if (config :debug) ".*" (config :domain-cli)))]
       
:access-control-allow-methods [:get :post])
     
(#(if (config :debug) (wrap-reload %)))))

(defn -main [& args]
 
;; Main

 
;; Run web server
 
(run-jetty wrapped-handler {:port (config :port)}))


To unsubscribe from this group and stop receiving emails from it, send an email to comp...@googlegroups.com.


--
James Reeves

James Reeves

unread,
Apr 28, 2020, 5:28:33 PM4/28/20
to Compojure
It looks like this line may be the problem:

(#(if (config :debug) (wrap-reload %)))))

If (config :debug) is false, then wrapped-handler is nil. You need to ensure that you have an "else" clause that returns the argument unaltered.

(#(if (config :debug) (wrap-reload %) %))))

Or use cond->

(cond-> (config :debug) wrap-reload))))


To unsubscribe from this group and stop receiving emails from it, send an email to compojure+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/compojure/6bfaffeb-1384-456c-81de-fdcccddc35ac%40googlegroups.com.


--
James Reeves

Andros Fenollosa

unread,
Apr 29, 2020, 9:55:27 AM4/29/20
to Compojure

Thank you and thank you! I was going crazy and I didn't know what to do anymore. My gratitude is eternal. Now I have finally finished my Open Source project.
I invite you to see where you helped me to place the last piece of the puzzle.

https://github.com/glosa/glosa-server

A hug :)

Reply all
Reply to author
Forward
0 new messages