From a18b971564647041f229dce7eff92e1133b7a7da Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 25 Jul 2021 10:16:56 +0200 Subject: [PATCH 1/2] Fix a racing condition that could lead to the sync getting stuck --- resources/lib/backgroundthread.py | 18 ++++++++++++++++++ .../lib/library_sync/fill_metadata_queue.py | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/resources/lib/backgroundthread.py b/resources/lib/backgroundthread.py index 43aee604..af360d9b 100644 --- a/resources/lib/backgroundthread.py +++ b/resources/lib/backgroundthread.py @@ -170,6 +170,24 @@ class ProcessingQueue(Queue.Queue, object): with self.mutex: self._add_section(section) + def change_section_number_of_items(self, section, number_of_items): + """ + Hit this method if you've reset section.number_of_items to make + sure we're not blocking + """ + with self.mutex: + self._change_section_number_of_items(section, number_of_items) + + def _change_section_number_of_items(self, section, number_of_items): + section.number_of_items = number_of_items + if (self._current_section == section + and self._counter == number_of_items): + # We were actually waiting for more items to come in - but there + # aren't any! + self._init_next_section() + if self._qsize() > 0: + self.not_empty.notify() + def _add_section(self, section): self._sections.append(section) self._queues.append( diff --git a/resources/lib/library_sync/fill_metadata_queue.py b/resources/lib/library_sync/fill_metadata_queue.py index a459b7af..b3bb5102 100644 --- a/resources/lib/library_sync/fill_metadata_queue.py +++ b/resources/lib/library_sync/fill_metadata_queue.py @@ -62,7 +62,8 @@ class FillMetadataQueue(common.LibrarySyncMixin, count += 1 # We might have received LESS items from the PMS than anticipated. # Ensures that our queues finish - section.number_of_items = count + self.processing_queue.change_section_number_of_items(section, + count) LOG.debug('%s items to process for section %s', section.number_of_items, section) From 262315c3e778566f074c25ebaa79df970f6d4af8 Mon Sep 17 00:00:00 2001 From: croneter Date: Sun, 25 Jul 2021 11:03:34 +0200 Subject: [PATCH 2/2] Fix Regression: AttributeError --- resources/lib/library_sync/sections.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/resources/lib/library_sync/sections.py b/resources/lib/library_sync/sections.py index 9fa67d5e..391aeb31 100644 --- a/resources/lib/library_sync/sections.py +++ b/resources/lib/library_sync/sections.py @@ -109,6 +109,8 @@ class Section(object): Sections compare equal if their section_id, name and plex_type (first prio) OR section_type (if there is no plex_type is set) compare equal """ + if not isinstance(section, Section): + return False return (self.section_id == section.section_id and self.name == section.name and (self.plex_type == section.plex_type if self.plex_type else