Uploaded image for project: 'Apache AsterixDB'
  1. Apache AsterixDB
  2. ASTERIXDB-1690

FileSystemWatcher.close() is blocked by FileSystemWatcher.take() when monitoring directory.

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: ING - Ingestion
    • Labels:
      None

      Description

      When create feed for directory monitoring, disconnect feed can be blocked by the FileSystemWatcher. When FileSystemWatcher is waiting for new files, the whole object is locked by current thread. So when another thread trying to close the watcher, it will be blocked. Here is the take() method from FileSystemWatcher:

       public synchronized File take() throws IOException {
              File next = poll();
              if (next != null) {
                  return next;
              }
              if (done || !isFeed) {
                  return null;
              }
              // No file was found, wait for the filesystem to push events
              WatchKey key = null;
              lock.lock();
              try {
                  while (!it.hasNext()) {
                      try {
                          key = watcher.take();
                      } catch (InterruptedException x) {
                          if (LOGGER.isEnabledFor(Level.WARN)) {
                              LOGGER.warn("Feed Closed");
                          }
                          if (watcher == null) {
                              return null;
                          }
                          continue;
                      } catch (ClosedWatchServiceException e) {
                          if (LOGGER.isEnabledFor(Level.WARN)) {
                              LOGGER.warn("The watcher has exited");
                          }
                          if (watcher == null) {
                              return null;
                          }
                          continue;
                      }
                      handleEvents(key);
                      if (endOfEvents(key)) {
                          return null;
                      }
                  }
              } finally {
                  lock.unlock();
              }
              // files were found, re-create the iterator and move it one step
              return it.next();
          }
      

        Attachments

          Activity

            People

            • Assignee:
              idleft Xikui Wang
              Reporter:
              idleft Xikui Wang
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: