question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

File monitor stops with FileSystemException when copying a large directory structure into the watched folder

See original GitHub issue

If I copy a large directory structure (the unzipped jmeter package as example) into a watched folder, then the FileMonitor stops with a java.nio.file.FileSystemException:

java.nio.file.FileSystemException: ...: The process cannot access the file because it is being used by another process.

        at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
        at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
        at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
        at sun.nio.fs.WindowsDirectoryStream.<init>(Unknown Source)
        at sun.nio.fs.WindowsFileSystemProvider.newDirectoryStream(Unknown Source)
        at java.nio.file.Files.newDirectoryStream(Unknown Source)
        at java.nio.file.FileTreeWalker.visit(Unknown Source)
        at java.nio.file.FileTreeWalker.walk(Unknown Source)
        at java.nio.file.FileTreeIterator.<init>(Unknown Source)
        at java.nio.file.Files.walk(Unknown Source)

I’ve tested this on Windows 7 with the following code:

val watcher = new FileMonitor(directory, recursive = true) {
  override def onEvent(eventType: WatchEvent.Kind[Path], file: File, count: Int) = eventType match {
    case EventType.ENTRY_CREATE => logger.info(s"$file got created")
    case EventType.ENTRY_MODIFY => logger.info(s"$file got modified $count")
    case EventType.ENTRY_DELETE => logger.info(s"$file got deleted")
  }
}
watcher.start()(context.system.dispatcher)

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:10 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
gmethvincommented, Dec 1, 2017

@pathikrit Yes, I’m already using it here: https://github.com/gmethvin/directory-watcher/#better-files-integration-scala. I think the File.Monitor interface is a good integration point for other libraries.

1reaction
gmethvincommented, Nov 9, 2017

@pathikrit The FILE_TREE part of it could be ported potentially but I’m not sure if you’re comfortable with the JNA dependency for the OS X implementation. Another option is to have a way to plug in alternate implementations for the file monitor in better-files, so I could create a library that provides the custom implementation.

Regarding this bug, the real issue is that there’s generally going to be a delay between the time a new directory is created and when we can register a listener on it. We’ll miss any events that happen during the time we weren’t listening. I don’t think there’s a foolproof way to eliminate that race condition without hooking into low-level OS functionality.

Read more comments on GitHub >

github_iconTop Results From Across the Web

"inotifywait -e close_write" ignores new folders in watch directory
The reason you're not seeing directories created from your script is that you're looking for CLOSE_WRITE instead of CREATE with IS_DIR :
Read more >
Wait for a folder and its content to be completely copied
Copying a large file involves one creation event and multiple Changed events because the file can't be created in a single operation. There's...
Read more >
A file copy operation fails when files or folders have long paths ...
In this scenario, the behavior of the copy operation is unreliable and fails because of the length of the file or folder path....
Read more >
3 ways to Copy a File From One Directory to Another in Java ...
io.File class, which provides a method to check if a file exists or not and methods for several other file operations but it...
Read more >
Monitor files and directories - Splunk Documentation
You perform the data collection on the forwarder and then send the data to the Splunk Cloud Platform instance. Forwarders have three file...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found