dgrnbrg / spiral

Like Ring, but built for core.async
Eclipse Public License 1.0
125 stars 6 forks source link

How can we use spiral and ring-reload together? #19

Open hantuzun opened 9 years ago

hantuzun commented 9 years ago

I've tried make spiral and ring-reload work together without success.

I'm getting the following error:

ERROR http-kit - Encountered unhandled error from spiral httpkit adapapter.
java.lang.Exception: Cyclic load dependency: [ /spock/core ]->/spock/rest->[ /spock/core ], compiling:(/private/var/folders/m5/tl2vtswn5sjb4jry7k6x30tr0000gn/T/form-init8541479910851221960.clj:1:198)
    at clojure.core$throw_if.doInvoke(core.clj:5630)
    at clojure.lang.RestFn.invoke(RestFn.java:442)
    at clojure.core$check_cyclic_dependency.invoke(core.clj:5766)
    at clojure.core$load.doInvoke(core.clj:5863)
    at clojure.lang.RestFn.invoke(RestFn.java:408)
    at clojure.core$load_one.invoke(core.clj:5671)
    at clojure.core$load_lib$fn__5397.invoke(core.clj:5711)
    at clojure.core$load_lib.doInvoke(core.clj:5710)
    at clojure.lang.RestFn.applyTo(RestFn.java:142)
    at clojure.core$apply.invoke(core.clj:632)
    at clojure.core$load_libs.doInvoke(core.clj:5749)
    at clojure.lang.RestFn.applyTo(RestFn.java:137)
    at clojure.core$apply.invoke(core.clj:632)
    at clojure.core$require.doInvoke(core.clj:5832)
    at clojure.lang.RestFn.invoke(RestFn.java:421)
    at ring.middleware.reload$wrap_reload$fn__471.invoke(reload.clj:17)
    at ring.middleware.json$wrap_json_body$fn__759.invoke(json.clj:46)
    at clojure.lang.Var.invoke(Var.java:379)
    at spiral.core$sync__GT_async_adapter$fn__5831$fn__5832.invoke(core.clj:48)
    at spiral.core$sync__GT_async_adapter$fn__5831.invoke(core.clj:47)
    at clojure.core.async$thread_call$fn__4086.invoke(async.clj:405)
    at clojure.lang.AFn.run(AFn.java:22)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
...

How can we resolve the issue?

Thanks!

dgrnbrg commented 9 years ago

This looks like a problem with the spock library--are you also using it?

hantuzun commented 9 years ago

Spock is the name of out project :)

dgrnbrg commented 9 years ago

I don't think spiral does anything weird with loading libs--could you share a simple reproducible case with me, so that I could debug it?

hantuzun commented 9 years ago

Sure thing, just give me a day or two.

dgrnbrg commented 9 years ago

Looking forward to it! On Mon, Aug 10, 2015 at 4:29 AM Emrehan Tüzün notifications@github.com wrote:

Sure thing, just give me a day or two.

— Reply to this email directly or view it on GitHub https://github.com/dgrnbrg/spiral/issues/19#issuecomment-129363113.

hantuzun commented 9 years ago

Here is it: https://github.com/emrehan/failing-spiral

dgrnbrg commented 9 years ago

Thanks, I'm looking into this over the next week or so, to come up with a fix! On Thu, Aug 13, 2015 at 7:46 AM Emrehan Tüzün notifications@github.com wrote:

Here is it: https://github.com/emrehan/failing-spiral

— Reply to this email directly or view it on GitHub https://github.com/dgrnbrg/spiral/issues/19#issuecomment-130635733.

dgrnbrg commented 9 years ago

I've got the repro working, and I've discovering a bizarre thing. If I first do a (require 'project.core :reload) and (require 'project.rest :reload), then the bug with ring-reload doesn't show up. It seems something very strange is going on with the namespace dependency tracking and the way that ring-reload handles it, as compared to when I do the requires myself (which seems to initialize something differently).

hantuzun commented 9 years ago

Oh, that's strange. The issue could be caused by Clojure compiler as well. CLJ-1544 had cost me some time back then.

dgrnbrg commented 9 years ago

I'm really not sure what's going on. I've further determined that even if I do those requires, then ring-reload definitely invokes using (require ... :reload), but also the source file is not reloaded, so it just silently fails.

Perhaps you could require the specific namespaces yourself from your editor? That's what I do.

hantuzun commented 9 years ago

@dgrnbrg; how could I require namespaces from an editor? I didn't get it.

dgrnbrg commented 9 years ago

Which editor do you use? I can give you specific instructions. Basically, most editors have a keyboard shortcut to do (require 'current-ns :reload) On Wed, Aug 26, 2015 at 8:32 AM Emrehan Tüzün notifications@github.com wrote:

@dgrnbrg https://github.com/dgrnbrg; how could I require namespaces from an editor? I didn't get it.

— Reply to this email directly or view it on GitHub https://github.com/dgrnbrg/spiral/issues/19#issuecomment-134984053.

hantuzun commented 9 years ago

Okay, I use Idea, but I can't see how doing (require 'current-ns :reload) would help a project run without problems.

dgrnbrg commented 9 years ago

Once you've got the server running, you can reload whichever namespace you're working in, so that all invocations to the new vars are picked up. Unfortunately, repl-driven development with core.async is hard, because it keeps old code running unless you shut it down cleanly.

On Thu, Aug 27, 2015 at 12:49 AM Emrehan Tüzün notifications@github.com wrote:

Okay, I use Idea, but I can't see how doing (require 'current-ns :reload) would help a project run without problems.

— Reply to this email directly or view it on GitHub https://github.com/dgrnbrg/spiral/issues/19#issuecomment-135290452.

hantuzun commented 9 years ago

Thanks. Would it help in production?

dgrnbrg commented 9 years ago

I would recommend against using ring-reload or anything like it in production--the best practice is to create an "uberjar" (which contains all your dependencies), so that you can trust the state of the deployment.

On Thu, Aug 27, 2015 at 10:18 AM Emrehan Tüzün notifications@github.com wrote:

Thanks. Would it help in production?

— Reply to this email directly or view it on GitHub https://github.com/dgrnbrg/spiral/issues/19#issuecomment-135449299.

hantuzun commented 9 years ago

Yes, you're right. We're running uberjars as well, but we should use ring-reload only in development profile.