fsnotify / fsnotify

Cross-platform filesystem notifications for Go.
BSD 3-Clause "New" or "Revised" License
9.56k stars 904 forks source link

fsnotify queue overflow #343

Closed luowencai closed 4 years ago

luowencai commented 4 years ago

Before reporting an issue, please ensure you are using the latest release of fsnotify.

Which operating system (GOOS) and version are you using?

Linux version 3.10.0-957.27.2.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Mon Jul 29 17:46:05 UTC 2019

cat /proc/sys/fs/inotify/max_queued_events 16384

fsnotify version:v1.4.9

Please describe the issue that occurred.

I notify four folder, write three file at the same time in folder /data/logs/nginx, after few second rename three file to the other three folder /data/a, /data/b, /data/c, and this error happen

Are you able to reproduce the issue? Please provide steps to reproduce and a code sample if possible.

    folderNotify, err := fsnotify.NewWatcher()
    if err != nil {
        panic(fmt.Sprintf("new fsnotify err=%v", err))
    }
    folderNotify.Add("/data/logs/nginx")
    folderNotify.Add("/data/a")
    folderNotify.Add("/data/b")
    folderNotify.Add("/data/c")
    for {
        select {
        case event, ok := <-folderNotify.Events:
            if !ok {
                return
            }
            //do something
            println(event.Name)
        case err, ok := <-folderNotify.Errors:
            if !ok {
                return
            }
            panic(fmt.Sprintf("notify folder error:%s", err.Error()))
        }
    }

test code


filea.php
$path = "/data/logs/nginx";
$fileList = [
    'a.log' => '/data/a',
];
foreach ($fileList as $file => $rotateFolder) {
    $date = date('Ymd_His');
    $fullPath = "{$path}/{$file}";
    $fp = fopen($fullPath, "w+");
    for ($i = 0; $i < 2000000; $i++) {
        fwrite($fp, $i . PHP_EOL);
    }
    $temp = "{$rotateFolder}/{$file}.{$date}";
    echo $temp . PHP_EOL;
    rename($fullPath, $temp);
    sleep(30);
    for ($i = 0; $i < 10000; $i++) {
        fwrite($fp, $i . PHP_EOL);
    }
    fclose($fp);
}

fileb.php
$path = "/data/logs/nginx";
$fileList = [
    'b.log' => '/data/b',
];
foreach ($fileList as $file => $rotateFolder) {
    $date = date('Ymd_His');
    $fullPath = "{$path}/{$file}";
    $fp = fopen($fullPath, "w+");
    for ($i = 0; $i < 2000000; $i++) {
        fwrite($fp, $i . PHP_EOL);
    }
    $temp = "{$rotateFolder}/{$file}.{$date}";
    echo $temp . PHP_EOL;
    rename($fullPath, $temp);
    sleep(30);
    for ($i = 0; $i < 10000; $i++) {
        fwrite($fp, $i . PHP_EOL);
    }
    fclose($fp);
}

filec.php
$path = "/data/logs/nginx";
$fileList = [
    'c.log' => '/data/c',
];
foreach ($fileList as $file => $rotateFolder) {
    $date = date('Ymd_His');
    $fullPath = "{$path}/{$file}";
    $fp = fopen($fullPath, "w+");
    for ($i = 0; $i < 2000000; $i++) {
        fwrite($fp, $i . PHP_EOL);
    }
    $temp = "{$rotateFolder}/{$file}.{$date}";
    echo $temp . PHP_EOL;
    rename($fullPath, $temp);
    sleep(30);
    for ($i = 0; $i < 10000; $i++) {
        fwrite($fp, $i . PHP_EOL);
    }
    fclose($fp);
}
luowencai commented 4 years ago

Should i ignore it?thx

luowencai commented 4 years ago

Too many write cause this error, fsnotify cannot consume it.

ChinaGISboyYang commented 7 months ago

请问,您解决这个问题了么