Fork me on GitHub

Hello allย ๐Ÿ™‚ I am seeing this in the logs of one of my apps:

java.lang.AssertionError: Assert failed: No more than 1024 pending takes are allowed on a single channel.
 (< (.size takes) impl/MAX-QUEUE-SIZE)" exceptionType=java.lang.AssertionError
This seems the likely culprit:
(defn consume-channels [channels result-chan]
  (doseq [out channels] 
          (if-let [msg (async/<!! out)]
            (do (async/>!! res-ch (do-something msg))
This is supposed to consume messages from a list of channels until the channels are closed. do-something is doing some io and takes ~10 seconds. How should this be rewritten to avoid the above error?

Ben Sless10:08:10

separate consuming from channels and processing first, i.e., async/merge Then do your IO in pipeline blocking downstream Second, I doubt this is the culprit. Why? The assertion tells you you have enqueued too many takes on one channel. In your function you start a new thread per channel and only one thread is taking from the channel, so per thread there is no more than one enqueued take on the channel

Ben Sless10:08:59

The problem is probably somewhere where you call take! , <! or <!! many times on one channel


I see, that makes sense, I will need to dig down where other take are done then. Thanks a lot

Ben Sless10:08:13

Welcome. do you have a call stack? maybe it will help


Yes, it points to the underlying throttled channel ( But this is only used in another place that I can see, which periodically checks that the channels can be created (a healthcheck)


I should have mentioned, the input argument "channels" are throttled channels.

Ben Sless10:08:30

If you can paste the entire error stack trace


of course:

2021-08-09T11:15:59.761+0100 ERROR Uncaught exception on async-dispatch-8571
java.lang.AssertionError: Assert failed: No more than 1024 pending takes are allowed on a single channel.
(< (.size takes) impl/MAX-QUEUE-SIZE)
	at clojure.core.async.impl.channels.ManyToManyChannel.take_BANG_(channels.clj:235)
	at clojure.core.async.impl.ioc_macros$take_BANG_.invokeStatic(ioc_macros.clj:988)
	at clojure.core.async.impl.ioc_macros$take_BANG_.invoke(ioc_macros.clj:987)
	at throttler.core$chan_throttler_STAR_$fn__32201$state_machine__11344__auto____32212$fn__32214.invoke(core.clj:38)
	at throttler.core$chan_throttler_STAR_$fn__32201$state_machine__11344__auto____32212.invoke(core.clj:35)
	at clojure.core.async.impl.ioc_macros$run_state_machine.invokeStatic(ioc_macros.clj:978)
	at clojure.core.async.impl.ioc_macros$run_state_machine.invoke(ioc_macros.clj:977)
	at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invokeStatic(ioc_macros.clj:982)
	at clojure.core.async.impl.ioc_macros$run_state_machine_wrapped.invoke(ioc_macros.clj:980)
	at clojure.core.async.impl.ioc_macros$take_BANG_$fn__11362.invoke(ioc_macros.clj:991)
	at clojure.core.async.impl.channels.ManyToManyChannel$fn__6980.invoke(channels.clj:265)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(
	at java.util.concurrent.ThreadPoolExecutor$
	at clojure.core.async.impl.concurrent$counted_thread_factory$reify__6818$fn__6819.invoke(concurrent.clj:29)
2021-08-09T11:15:59.761+0100 INFO exceptionCaller=throttler.core$chan_throttler_STAR_$fn__32201$state_machine__11344__auto____32212$fn__32214# exceptionCallerClass=throttler.core$chan_throttler_STAR_$fn__32201$state_machine__11344__auto____32212$fn__32214 exceptionCallerLineNo=38 exceptionCallerMethod=invoke exceptionData=null exceptionMessage="Assert failed: No more than 1024 pending takes are allowed on a single channel.

Ben Sless11:08:13

Hard to say where the bug is, exactly, but I think you should open an issue to the library

Ben Sless11:08:28

Did you set a bucket size?


yes, though the bucket size is computed and might be too big (> 1024)


so I will check that first ๐Ÿ™‚ thanks a lot for you help


oh. what is bucketing? I suspect I donโ€™t need it, just need throttling

Ben Sless11:08:07

bucketing is more tolerant throttling, lets you send bursts


ah you mean the bucketing algorithm I guess


yes I see ๐Ÿ™‚ not sure about this since it is for an external API and the limits there are not clear

Ben Sless11:08:48

They never are ๐Ÿ™‚


but Iโ€™ll keep that in mind. Thanks a lot for your help!


ahah indeed ๐Ÿ˜›

Ben Sless11:08:07

you can connect it with a circuit breaker if you're not sure

Ben Sless11:08:34

then connect it with diehard to send negative feedback


very interesting! ๐Ÿ™‚ I will check more.async

๐Ÿ™ƒ 4
Ben Sless11:08:45

breaker-pipe -> rate-limiter -> (IO + CB) Close over the CB in the function you pass to breaker-pipe, then if you trip it, the breaker will open up stream


๐Ÿ™‚ sounds good to me