Welcome! Please see the About page for a little more info on how this works.

0 votes
in core.async by

We encountered a thorny problem with core.async:

In some situations "No more than 1024 pending takes are allowed" is raised in an async-dispatch thread, even though there are actually only 1024 pending takes.
That situation can be triggered quickly with the following code:

`
(dotimes [_ 5000]
;; - start 1024 threads that all alt! on a common channel (ch) and on an individual channel (x)
;; - the common channel remains 'empty' all the time
;; - wakeup all theads twice via the x channel, which makes them loop.
;; - this quickly raises multiple 'No more than 1024 pending takes are allowed on a single channel.' assertions in an async-dispatch thread.
(let [ch (async/chan)

    threads clojure.core.async.impl.protocols/MAX-QUEUE-SIZE
    wakeups 2
    x-chans
    (mapv (fn [n]
            (let [x (async/chan)]
              (async/go-loop []
                (async/alt!
                  ch nil
                  x ([_] (recur))))
              x))
          (range threads))]
(doseq [x x-chans]
  (dotimes [n wakeups]
    (async/>!! x 42)))
(async/close! ch)))

`

Environment:
Mac OS, JDK 8, Clojure 1.10.0, core-async 0.6.532

Please log in or register to answer this question.

...