Skip to content

Commit d24e3bf

Browse files
committed
Only ignore IOException when fsyncing on dirs (#42972)
Today in the method IOUtils#fsync we ignore IOExceptions when fsyncing a directory. However, the catch block here is too broad, for example it would be ignoring IOExceptions when we try to open a non-existant file. This commit addresses that by scoping the ignored exceptions only to the invocation of FileChannel#force.
1 parent e64138a commit d24e3bf

File tree

1 file changed

+12
-10
lines changed
  • libs/core/src/main/java/org/elasticsearch/core/internal/io

1 file changed

+12
-10
lines changed

libs/core/src/main/java/org/elasticsearch/core/internal/io/IOUtils.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,19 @@ public FileVisitResult visitFileFailed(final Path file, final IOException exc) t
264264
*/
265265
public static void fsync(final Path fileToSync, final boolean isDir) throws IOException {
266266
try (FileChannel file = FileChannel.open(fileToSync, isDir ? StandardOpenOption.READ : StandardOpenOption.WRITE)) {
267-
file.force(true);
268-
} catch (final IOException ioe) {
269-
if (isDir) {
270-
assert (LINUX || MAC_OS_X) == false :
271-
"on Linux and MacOSX fsyncing a directory should not throw IOException, "+
272-
"we just don't want to rely on that in production (undocumented); got: " + ioe;
273-
// ignore exception if it is a directory
274-
return;
267+
try {
268+
file.force(true);
269+
} catch (final IOException e) {
270+
if (isDir) {
271+
assert (LINUX || MAC_OS_X) == false :
272+
"on Linux and MacOSX fsyncing a directory should not throw IOException, "+
273+
"we just don't want to rely on that in production (undocumented); got: " + e;
274+
// ignore exception if it is a directory
275+
return;
276+
}
277+
// throw original exception
278+
throw e;
275279
}
276-
// throw original exception
277-
throw ioe;
278280
}
279281
}
280282
}

0 commit comments

Comments
 (0)