Skip to content

Undocumented "no events" Op on Linux when a watched directory is unmounted #655

@kivattt

Description

@kivattt

When a watched directory is unmounted/deleted? on Linux, fsnotify emits an event with the Op value 0 ("no events") up to ~1 minute later.
This happens when I plug in my camera via USB, let dolphin mount it, watching a mounted subdirectory with fsnotify, and then shutting off my camera.

I could only find this "no events" event mentioned under the "Windows notes" section of the documentation

image
This happens in fsnotify v1.7.0 and v1.8.0

$ uname -a
Linux kivah 5.15.0-119-generic #129-Ubuntu SMP Fri Aug 2 19:25:20 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Distro: Linux Mint 21.3 x86_64

Code to reproduce (click to expand)
package main

import (
        "fmt"

        "github.com/fsnotify/fsnotify"
)

func main() {
        watcher, _ := fsnotify.NewWatcher()
        defer watcher.Close()

        watcher.Add("/mounted-directory/subdirectory")

        go func() {
                for {
                        select {
                        case event, ok := <-watcher.Events:
                                if !ok {
                                        return
                                }
                                fmt.Println(event)
                        case _, ok := <-watcher.Errors:
                                if !ok {
                                        return
                                }
                        }
                }
        }()

        select {}
}

It would be nice to document that the received event.Op can be 0 in the Watcher struct documentation comments, especially since it can happen on both Windows & Linux.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions