Skip to content

Commit

Permalink
retry metadata requests upon timeout (#283)
Browse files Browse the repository at this point in the history
* retry metadata requests upon timeout

* reorg

* changelog

* sleep timeout
  • Loading branch information
mensfeld authored Dec 9, 2022
1 parent bc393d6 commit a6a1f16
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# WaterDrop changelog

## Unreleased
- Add temporary patch on top of `rdkafka-ruby` to mitigate metadata fetch timeout failures.

## 2.4.3 (2022-12-07)
- Support for librdkafka 0.13
- Update Github Actions
Expand Down
36 changes: 36 additions & 0 deletions lib/waterdrop/patches/rdkafka/metadata.rb
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

0 comments on commit a6a1f16

Please sign in to comment.