tant

tant

Broadway Producer does not receive incoming_demand from the consumer

Hi everyone,

I’m having an issue while using Broadway: the producer is not receiving any demand, so handle_demand/2 is never called. I’ve tried debugging but haven’t been able to identify the cause yet.

Issue Summary

I have a custom UDP Producer built on top of GenStage and 1,000 Consumers. The system is initialized following Broadway’s recommended configuration. Each Consumer is set up to process only one demand at a time. I then send 1 million UDP messages over the course of one minute. Initially, some messages are processed smoothly, although slowly; however, processing eventually slows down and stops entirely. Upon checking, I noticed that the handle_demand/2 callback in the Producer is no longer being invoked, which causes the system to stall.

You can find the sample code for the UDP implementation in this repository:
GitHub - thachtanapsi/my_udp_app

Environment

  • Erlang/OTP 27 [erts-15.2.7]
  • Elixir: 1.18.3
  • OS: Ubuntu 24.04.1 LTS
  • Broadway: 1.2.1
  • GenStage: 1.3.1

Most Liked

tant

tant

:hammer_and_wrench: Root Cause Found: Missing Demand Due to Hidden Recursive Call

After receiving valuable guidance from my manager TamLeDuc :folded_hands:, I was able to identify the root cause behind the issue where handle_demand/2 was not being triggered, even though messages were continuously arriving.

:magnifying_glass_tilted_left: Root Cause:
There was a hidden recursive call in the message handling logic that wasn’t immediately obvious. The function lacked a clear stopping condition and had no timeout mechanism, which led to:

  • The process getting stuck in an infinite loop.
  • It never returning control to receive incoming demands.
  • Broadway not being able to push new demand, causing the system to appear frozen.

:light_bulb: This was particularly tricky because it didn’t produce any crash or clear stacktrace. The process simply hung, leading to the false impression that the system was overloaded or disconnected.

:bullseye: Solution:

  • Refactored the recursive logic to ensure controlled flow.
  • Added limits or timeouts to prevent long waits.
  • Placed logs at the start and end of handler functions to better detect processing bottlenecks in the future.

Thanks again to TamLeDuc for the direction and to everyone who took the time to look into this — your support helped save a lot of debugging hours! :raising_hands:

:backhand_index_pointing_right: And big thanks to everyone who stopped by or took a moment to read this post — I really appreciate your time and attention! :folded_hands:

lud

lud

Hello,

Welcome to the forums :slight_smile:

I’m tinkering with your app. I can observe packet loss when sending a million messages but the handler are called, meaning the demand is properly registered and served.

Now if the producer process is overloaded with UDP messages, as it is in active mode, it will take time to receive the demand messages.

lud

lud

Maybe you need more unit tests!

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
script
If I have a string “1000 cfu/ml” . I want to remove the characters and / and space . So the string is like this "1000" What is the ...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Exadra37
Sometimes I want to check if the input into a function is not a blank string. My first approach: defmodule Example do def do_stuff(s...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New

We're in Beta

About us Mission Statement