Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-8663

NRTCachingDirectory.slowFileExists may open a file while it's inaccessible

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • 9.0
    • None
    • None
    • New

    Description

      This build:
      https://builds.apache.org/job/Lucene-Solr-NightlyTests-master/1761/consoleText

      failed with the following stack trace:

      FAILED:  org.apache.lucene.util.TestOfflineSorter.testThreadSafety
      
      Error Message:
      Captured an uncaught exception in thread: Thread[id=2665, name=Thread-2493, state=RUNNABLE, group=TGRP-TestOfflineSorter]
      
      Stack Trace:
      com.carrotsearch.randomizedtesting.UncaughtExceptionError: Captured an uncaught exception in thread: Thread[id=2665, name=Thread-2493, state=RUNNABLE, group=TGRP-TestOfflineSorter]
      Caused by: java.lang.RuntimeException: java.nio.file.AccessDeniedException: Can't open a file still open for writing: unsorted_tmp_0.tmp
              at __randomizedtesting.SeedInfo.seed([972EEC94E272C842]:0)
              at org.apache.lucene.util.TestOfflineSorter$2.run(TestOfflineSorter.java:271)
      Caused by: java.nio.file.AccessDeniedException: Can't open a file still open for writing: unsorted_tmp_0.tmp
              at org.apache.lucene.store.ByteBuffersDirectory$FileEntry.openInput(ByteBuffersDirectory.java:250)
              at org.apache.lucene.store.ByteBuffersDirectory.openInput(ByteBuffersDirectory.java:222)
              at org.apache.lucene.store.NRTCachingDirectory.slowFileExists(NRTCachingDirectory.java:292)
              at org.apache.lucene.store.NRTCachingDirectory.createTempOutput(NRTCachingDirectory.java:266)
              at org.apache.lucene.store.MockDirectoryWrapper.createTempOutput(MockDirectoryWrapper.java:697)
              at org.apache.lucene.util.TestOfflineSorter.checkSort(TestOfflineSorter.java:183)
              at org.apache.lucene.util.TestOfflineSorter.access$100(TestOfflineSorter.java:49)
              at org.apache.lucene.util.TestOfflineSorter$2.run(TestOfflineSorter.java:267)
      

      The problem in slowFileExists is that it probes for file existence by trying to open it in a directory. We don't allow opening files that are still open by another thread (for writing), hence the exception thrown is AccessDeniedException.

      I couldn't reproduce the problem with the same seed. Takes some luck to hit the right scenario in a multi-threaded run.

      The contract for Directory.fileLength is less strict so a straightforward patch is to use that instead.

      Attachments

        1. LUCENE-8663.patch
          2 kB
          Dawid Weiss

        Activity

          People

            dweiss Dawid Weiss
            dweiss Dawid Weiss
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: