From 51c4d1851b1e65fc6fcc8a71dd5fc99f51e09a83 Mon Sep 17 00:00:00 2001 From: Jason Woods Date: Tue, 23 Nov 2021 11:28:27 +0000 Subject: [PATCH] Fix high CPU reload deadlock in publisher --- CHANGELOG.md | 1 + lc-lib/internallist/list.go | 8 ++++++++ lc-lib/publisher/endpoint/sink_list.go | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 343daf519..1ae985230 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Log Courier / Log Carver - Fixed crash during configuration reload for `tcp` receiver and transport - Fixed reload of configuration not correctly updating endpoints +- Fixed reload of configuration sometimes causing a deadlock with hugh CPU ## 2.8.0 diff --git a/lc-lib/internallist/list.go b/lc-lib/internallist/list.go index 723186291..3832cb440 100644 --- a/lc-lib/internallist/list.go +++ b/lc-lib/internallist/list.go @@ -129,13 +129,21 @@ func (l *List) Remove(e *Element) interface{} { } // PushFront inserts a new element e at the front of list l and returns e. +// Does nothing and returns e if the item is already in a list. func (l *List) PushFront(e *Element) *Element { + if e.list != nil { + return e + } l.lazyInit() return l.insert(e, &l.root) } // PushBack inserts a new element e at the back of list l and returns e. +// Does nothing and returns e if the item is already in a list. func (l *List) PushBack(e *Element) *Element { + if e.list != nil { + return e + } l.lazyInit() return l.insert(e, l.root.prev) } diff --git a/lc-lib/publisher/endpoint/sink_list.go b/lc-lib/publisher/endpoint/sink_list.go index 71ec51376..7f138570c 100644 --- a/lc-lib/publisher/endpoint/sink_list.go +++ b/lc-lib/publisher/endpoint/sink_list.go @@ -83,7 +83,7 @@ func (s *Sink) AddEndpointAfter(server string, addressPool *addresspool.Pool, af if after == nil { s.orderedList.PushFront(&endpoint.orderedElement) } else { - s.orderedList.MoveAfter(&endpoint.orderedElement, &after.orderedElement) + s.orderedList.InsertAfter(&endpoint.orderedElement, &after.orderedElement) } if s.api != nil { s.api.AddEntry(server, endpoint.apiEntry()) @@ -107,7 +107,7 @@ func (s *Sink) FindEndpoint(server string) *Endpoint { func (s *Sink) MoveEndpointAfter(endpoint *Endpoint, after *Endpoint) { if after == nil { s.mutex.Lock() - s.orderedList.PushFront(&endpoint.orderedElement) + s.orderedList.MoveToFront(&endpoint.orderedElement) s.mutex.Unlock() return }