Skip to content

Properly handle command errors (e.g. OOM) #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions lib/logstash/outputs/redis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,7 @@ def receive(event)
@redis.publish(key, payload)
end
rescue => e
@logger.warn("Failed to send event to Redis", :event => event,
:identity => identity, :exception => e,
:backtrace => e.backtrace)
sleep @reconnect_interval
@redis = nil
on_send_error(e, true)
retry
end
end # def receive
Expand All @@ -200,15 +196,29 @@ def flush(events, key, close=false)
@redis.rpush(key, events)
end
# called from Stud::Buffer#buffer_flush when an error occurs
def on_flush_error(e)
def on_send_error(e, _sleep=false)
if e.is_a?(Redis::CommandError)
@logger.warn("Redis write rejected: #{e.message}", :identity => identity)
sleep @reconnect_interval if _sleep
return
end

@logger.warn("Failed to send backlog of events to Redis",
:identity => identity,
:exception => e,
:backtrace => e.backtrace
)

begin
@redis.disconnect
rescue
end
sleep @reconnect_interval if _sleep
@redis = connect
end

alias_method :on_flush_error, :on_send_error

def close
if @batch
buffer_flush(:final => true)
Expand Down