Skip to content

Commit

Permalink
ENG-2031: Fixed the bug!
Browse files Browse the repository at this point in the history
This is an ugly fix that I'm going to try and simplify. The blast
radius for these changes is larger than necessary, so I want to try
a simpler fix.
  • Loading branch information
CuriousCurmudgeon committed Oct 16, 2024
1 parent a5b9576 commit 0a525bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/broadway/topology/producer_stage.ex
Original file line number Diff line number Diff line change
Expand Up @@ -422,9 +422,12 @@ defmodule Broadway.Topology.ProducerStage do
Utility.maybe_log("Remaining rate limit: #{left}", state)

cond do
messages == [] ->
messages == [] and next_message_weight == 0 ->
{:open, [], []}

messages == [] ->
{:closed, [], []}

# If no more messages are allowed, we're rate limited but we're able
# to emit all messages that we have.
left == 0 ->
Expand Down
4 changes: 4 additions & 0 deletions lib/broadway/topology/rate_limiter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ defmodule Broadway.Topology.RateLimiter do
end
end

def rate_limit(counter, 0) when is_reference(counter) do
get_currently_allowed(counter)
end

def rate_limit(counter, amount)
when is_reference(counter) and is_integer(amount) and amount > 0 do
:atomics.sub_get(counter, @atomics_index, amount)
Expand Down

0 comments on commit 0a525bd

Please sign in to comment.