From 1355f8c49e365918cffc8763303394638bd38bf8 Mon Sep 17 00:00:00 2001 From: Nicolas F Date: Thu, 25 Jun 2020 15:30:54 +0200 Subject: [PATCH] world: retry chunk read on OSError too Closes #1790. If a chunk fails reading due to an underlying operating system IO error, we can invoke the retry logic too. No clue what could cause this to happen beyond hardware faults. Also lower the sleep time to 0.25s down from 0.5s because half a second of sleeping for each chunk this happens on seems incredibly overkill. Making the nbt code raise a CorruptChunkError in this case also means that failing to read a chunk due to an IOError is not a fatal error anymore, it'll simply skip it and move on. --- overviewer_core/nbt.py | 5 ++++- overviewer_core/world.py | 9 ++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/overviewer_core/nbt.py b/overviewer_core/nbt.py index 7a8ee46..37e3770 100644 --- a/overviewer_core/nbt.py +++ b/overviewer_core/nbt.py @@ -292,7 +292,10 @@ class MCRFileReader(object): self._file.seek(offset) # read in the chunk data header - header = self._file.read(5) + try: + header = self._file.read(5) + except OSError as e: + raise CorruptChunkError("An OSError occurred: {}".format(e.strerror)) if len(header) != 5: raise CorruptChunkError("chunk header is invalid") data_length, compression = self._chunk_header_format.unpack(header) diff --git a/overviewer_core/world.py b/overviewer_core/world.py index f1d67a0..e121002 100644 --- a/overviewer_core/world.py +++ b/overviewer_core/world.py @@ -1355,12 +1355,11 @@ class RegionSet(object): except nbt.CorruptionError as e: tries -= 1 if tries > 0: - # Flush the region cache to possibly read a new region file - # header - logging.debug("Encountered a corrupt chunk at %s,%s. Flushing cache and retrying", x, z) - #logging.debug("Error was:", exc_info=1) + # Flush the region cache to possibly read a new region file header + logging.debug("Encountered a corrupt chunk or read error at %s,%s. " + "Flushing cache and retrying", x, z) del self.regioncache[regionfile] - time.sleep(0.5) + time.sleep(0.25) continue else: logging.warning("The following was encountered while reading from %s:", self.regiondir)