lein ring server does not pick up *some* code changes

187 views
Skip to first unread message

Dragan Djuric

unread,
Oct 25, 2011, 7:21:15 AM10/25/11
to Clojure Web Development
Hi I have noticed a strange behavior when developing a ring/compojure
baed application with lein-ring plugin. If I create a middleware
wrapper in the same namespace/file as the file where I define the main
handler everything works as expected and the changes in code are
evaluated.
However, if I define the same middleware wrapper in another file, the
changes in code are not picked up by lein-ring. I have to run lein
ring server command again.

Is it a bug, feature, or I just missed some configuration detail?

Mark Rathwell

unread,
Oct 25, 2011, 2:21:24 PM10/25/11
to clojure...@googlegroups.com
Changes to middleware is a different situation than changes to
supporting functions in that the middleware functions are executed
only once at startup, with the result being the ring handler. So,
changes to actual middleware functions will generally require you to
restart the server. I think the reason it works when you make those
changes in the same file as the ring handler definition is because
that file is then reloaded, and so the ring handler is also reloaded.

- Mark

James Reeves

unread,
Oct 25, 2011, 2:49:54 PM10/25/11
to clojure...@googlegroups.com
On 25 October 2011 14:21, Mark Rathwell <mark.r...@gmail.com> wrote:
> Changes to middleware is a different situation than changes to
> supporting functions in that the middleware functions are executed
> only once at startup, with the result being the ring handler.  So,
> changes to actual middleware functions will generally require you to
> restart the server.

This isn't actually correct. The lein-ring plugin references the
handler as a var, meaning that if you redefine the handler function,
the Jetty adapter will automatically know about the changes.

- James

James Reeves

unread,
Oct 25, 2011, 2:49:33 PM10/25/11
to clojure...@googlegroups.com
On 25 October 2011 07:21, Dragan Djuric <drag...@gmail.com> wrote:
> Hi I have noticed a strange behavior when developing a ring/compojure
> baed application with lein-ring plugin. If I create a middleware
> wrapper in the same namespace/file as the file where I define the main
> handler everything works as expected and the changes in code are
> evaluated.
> However, if I define the same middleware wrapper in another file, the
> changes in code are not picked up by lein-ring. I have to run lein
> ring server command again.

This sounds like the ring-reload-modified middleware is not correctly
resolving dependencies between source files.

In theory, if your handler file A depends on another file B, then
changing B will reload both A and B.

Could you post the "ns" declaration from the file that contains your
handler, and tell us which namespace your middleware function is in?

- James

Mark Rathwell

unread,
Oct 25, 2011, 4:25:32 PM10/25/11
to clojure...@googlegroups.com

I think we're saying the same thing, maybe not though. When you
redefine a middleware function you are not redifining the handler,
correct? And that existing handler already has the old middleware
added, right? My understanding is that the redefining of the handler
occurred when that file that defined it was changed and reloaded.
Apologies if I'm misunderstanding things.

Reply all
Reply to author
Forward
0 new messages