From c833d5ef3bd8fedf465977c396784dc3ca9ff2de Mon Sep 17 00:00:00 2001 From: Zlatin Balevsky Date: Mon, 29 Aug 2022 13:37:19 +0100 Subject: [PATCH] retry hashing on FileNotFoundExceptions, GitHub issue #167 --- .../main/groovy/com/muwire/core/files/FileHasher.groovy | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/src/main/groovy/com/muwire/core/files/FileHasher.groovy b/core/src/main/groovy/com/muwire/core/files/FileHasher.groovy index fd763c587..46aa44310 100644 --- a/core/src/main/groovy/com/muwire/core/files/FileHasher.groovy +++ b/core/src/main/groovy/com/muwire/core/files/FileHasher.groovy @@ -87,6 +87,13 @@ class FileHasher { byte[] hashList = output.toByteArray() return InfoHash.fromHashList(hashList) + } catch (FileNotFoundException weird) { + if (file.exists()) { + // this is apparently possible on some systems while the file is being used + // by another process, see GitHub issue 167. So we try again. + Thread.sleep(10) + } else + break // give up } catch (InternalError bad) { // nothing we can but try again. Happens on jre 18.0.1 log.log(Level.SEVERE,"internal error while hashing", bad)