From 7f660e91efc284b8d1596503571ed35153b2617f Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Mon, 18 Jan 2016 11:53:47 +0800 Subject: [PATCH] fix: workaround for some worker not autherized. username and password are correct. but cannot login when first insert occur. This patch avoid continue to use the not autherized connection and try to re-login. --- lib/logstash/outputs/mongodb.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/logstash/outputs/mongodb.rb b/lib/logstash/outputs/mongodb.rb index ce853a8..c80cdeb 100644 --- a/lib/logstash/outputs/mongodb.rb +++ b/lib/logstash/outputs/mongodb.rb @@ -63,6 +63,14 @@ def receive(event) # and generate a new primary key. # If the duplicate key error is on another field, we have no way # to fix the issue. + elsif e.message =~ /^not authorized/ + # Sometime worker cannot login when first insert. + # Re-login can resolve this not authorized problem. + @logger.warn("Not authorized, re-login...") + conn = Mongo::Client.new(@uri) + @db = conn.use(@database) + sleep @retry_delay + retry else sleep @retry_delay retry