clojure-dev

Issues: https://clojure.atlassian.net/browse/CLJ | Guide: https://insideclojure.org/2015/05/01/contributing-clojure/
arohner 2019-10-09T21:07:30.000600Z

I have what appears to be a locals-clearing bug when using core.async thread

(let [close? (promise)
      thread-ch (a/go-loop []
                  (when (not (realized? close?))
                    (try
                      (stuff))
                    (recur)))]
  (closeable thread-ch (fn [thread-ch]
                         (deliver close? true)
                         (a/<!! thread-ch))))

arohner 2019-10-09T21:08:22.001600Z

this code works. Swapping the go-loop for a/thread reliably causes an NPE when attempting (realized? close?)

arohner 2019-10-09T21:09:24.002400Z

println debugging shows close? to be a promise in in the first iteration through the code, and nil in the second

2019-10-09T21:19:50.004500Z

what version of clojure and core.async? a more minimal repeatable case would be great. I did the minimal to get that to compile with the core.async 0.4.500 and clojure 1.10.1 (basically just defining the free names) and it runs without errors here

2019-10-09T21:21:14.005Z

Oh, sorry I misread, that is the passing case, thread is the failing case

2019-10-09T21:21:25.005300Z

Yep, fails here too

2019-10-09T21:22:16.006200Z

it would be useful to isolate it without core.async, because thread doesn't do any code transforms so any behavior you get there should be repeatable elsewhere

arohner 2019-10-09T21:23:27.006500Z

alright

2019-10-09T21:23:30.006700Z

oh, I know what it is

2019-10-09T21:23:46.007100Z

you are replacing go-loop with thread without adding in a loop form

arohner 2019-10-09T21:24:05.007600Z

ah

arohner 2019-10-09T21:24:34.008400Z

yep, that’s it

2019-10-09T21:24:42.008800Z

which doesn't error when compiling because the recur just hits the fn introduced by thread, but errors when running because it's a :once fn

arohner 2019-10-09T21:24:50.009100Z

(a/thread (loop []…) works

arohner 2019-10-09T21:27:34.009300Z

thanks

ghadi 2019-10-09T21:45:55.009600Z

should :once fns be allowed to recur?

ghadi 2019-10-09T21:46:33.010100Z

the function is still being invoked a single time, but has an internal goto to recur

2019-10-09T21:51:23.010900Z

it seems like they should not, but it seems like the kind of thing someone somewhere is depending on