Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does this simple monitoring app result in a permission denied error on file event? #294

Closed
bbarker opened this issue Mar 28, 2021 · 7 comments

Comments

@bbarker
Copy link

bbarker commented Mar 28, 2021

Not sure if this is more of a question or a bug, so I'll fill out the below.

System details

  • OS/Platform name and version:
    NixOS:

    • system: "x86_64-linux"
    • host os: Linux 5.4.50, NixOS, 20.09.1889.58f9c4c7d3a (Nightingale)
    • multi-user?: yes
    • sandbox: yes
    • version: nix-env (Nix) 2.3.7
    • channels(nixos): ""
    • channels(root): "nixos-20.09.1889.58f9c4c7d3a"
    • channels(brandon): ""
    • nixpkgs: /nix/var/nix/profiles/per-user/root/channels/nixos
  • Rust version (if building from source): rustc --version:

    • rustc 1.52.0-nightly (f98721f88 2021-03-10)
  • Notify version (or commit hash if building from git):

    • 5.0.0-pre.6
  • If you're coming from a project that makes use of Notify, what it is, and a link to the downstream issue if there is one:

  • Filesystem type and options:

    • ext4
  • If you're running as a privileged user (root, System):

    • No, running as a regular user
  • If you're running in a VM, details on the hypervisor:

    • I believe this is running in KVM (in OpenStack)

What you did (as detailed as you can)

I wrote a small program (just starting it) to monitor files in a given directory. The relevant snippet:

pub fn cappend(src: &str, dst: &str) -> Result<()> {
    println!("Hello from cappend");
    let mut watcher: RecommendedWatcher = Watcher::new_immediate(|res| {
        println!("Debug: received an event");
        match res {
            Ok(event) => println!("event: {:?}", event),
            Err(e) => println!("watch error: {:?}", e),
        }
    })?;
    watcher
        .configure(Config::PreciseEvents(true))
        .context("Error configuring watcher for PreciseEvents")?;

    let src = PathDir::create(src)?;
    watch_dir(&mut watcher, &src)?;
    Ok(())
}

fn watch_dir(watcher: &mut RecommendedWatcher, dir: &PathDir) -> notify::Result<()> {
    watcher.watch(dir.as_path(), RecursiveMode::Recursive)?;
    Ok(())
}

What you expected

I expected the program to keep running - I don't know why there would be a permission denied error in this program, especially since there are no writes, and it is just looking at a folder in my home directory with these permissions:

$ ls -last ~/workspace
total 716
  0 -rw-r--r--  1 brandon users       0 Mar 28 13:50 foo.txt
  4 drwxr-xr-x 60 brandon users    4096 Mar 28 13:50 .
  4 drwx------ 29 brandon users    4096 Mar 26 01:12 ..

What happened

After running the program and initiating a filesystem action in another terminal (touch ~/workspace/foo.txt), I received an error and the program exited:

$ ./target/debug/contappend /home/brandon/workspace/ /tmp                                                                                                                                                                                                                                                                                              Hello from cappend
Debug: received an event
Error in cappend: Permission denied (os error 13)
@bbarker
Copy link
Author

bbarker commented Apr 1, 2021

Running this on a different system (Ubuntu 20.04, bare metal, no-VM), seems to indicate a different OS error ("No space left on device"), which is odd - every non-snap volume listed by df indicates ample free space.

$ ./target/debug/contappend ~/workspace/ /tmp/
Hello from cappend
Debug: received an event
Error in cappendevent: Event { kind: Create(File), paths: ["/home/brandon/workspace/foo.txt"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None }
: Debug: received an event
event: Event { kind: Modify(Metadata(Any)), paths: ["/home/brandon/workspace/foo.txt"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None }
No space left on device (os error 28)Debug: received an event

event: Event { kind: Access(Close(Write)), paths: ["/home/brandon/workspace/foo.txt"], attr:tracker: None, attr:flag: None, attr:info: None, attr:source: None }

@0xpr03
Copy link
Member

0xpr03 commented Apr 1, 2021

No space left on device

See also #266 - are you sure that you aren't at the inotify cap ?

@0xpr03
Copy link
Member

0xpr03 commented Apr 1, 2021

Depending on the settings and applications you're running, as well as how big the folder is you want to watch, you may already reach a limit.

@bbarker
Copy link
Author

bbarker commented Apr 1, 2021

Ah, I see - makes sense. I think you are right about that. It is a very large folder.

@bbarker bbarker closed this as completed Apr 1, 2021
@0xpr03
Copy link
Member

0xpr03 commented Apr 1, 2021

Note that you can increase your limits (system and user wide). Look for fs.inotify.max_user_watches on linux.

@0xpr03
Copy link
Member

0xpr03 commented Apr 1, 2021

Regarding your readme: You can use https://docs.rs/notify/5.0.0-pre.6/notify/poll/struct.PollWatcher.html instead to use a polling based watcher.

@bbarker
Copy link
Author

bbarker commented Apr 2, 2021

Thanks! I added some notes for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants