From 6874f41739055c34b555058a37db08645c74e6d6 Mon Sep 17 00:00:00 2001 From: Joshua Powers Date: Wed, 24 Jul 2024 08:24:34 -0600 Subject: [PATCH] fix(inputs.tail): Prevent deadlock when closing and max undelivered lines hit (#15649) --- plugins/inputs/tail/tail.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/inputs/tail/tail.go b/plugins/inputs/tail/tail.go index f6a71aaf3..95d6ea851 100644 --- a/plugins/inputs/tail/tail.go +++ b/plugins/inputs/tail/tail.go @@ -370,6 +370,11 @@ func (t *Tail) receiver(parser telegraf.Parser, tailer *tail.Tail) { select { case <-t.ctx.Done(): return + // Tail is trying to close so drain the sem to allow the receiver + // to exit. This condition is hit when the tailer may have hit the + // maximum undelivered lines and is trying to close. + case <-tailer.Dying(): + <-t.sem case t.sem <- empty{}: t.acc.AddTrackingMetricGroup(metrics) }