-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
retry metadata requests upon timeout (#283)
* retry metadata requests upon timeout * reorg * changelog * sleep timeout
- Loading branch information
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
module WaterDrop | ||
# Patches to external components | ||
module Patches | ||
# Rdkafka related patches | ||
module Rdkafka | ||
# Rdkafka::Metadata patches | ||
module Metadata | ||
# We overwrite this method because there were reports of metadata operation timing out | ||
# when Kafka was under stress. While the messages dispatch will be retried, this was not | ||
# and was causing problems. | ||
# | ||
# @param args [Array<Object>] all the metadata original arguments | ||
def initialize(*args) | ||
attempt ||= 0 | ||
attempt += 1 | ||
|
||
super(*args) | ||
rescue Rdkafka::RdkafkaError => e | ||
raise unless e.code == :timed_out | ||
raise if attempt > 10 | ||
|
||
backoff_factor = 2**attempt | ||
timeout = backoff_factor * 0.1 | ||
|
||
sleep(timeout) | ||
|
||
retry | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
::Rdkafka::Metadata.prepend ::WaterDrop::Patches::Rdkafka::Metadata |