Skip to content

Watch triggers multiple times for non-markdown on APFS (macOS) #2133

@bgotink

Description

@bgotink

Problem

Editing non-.md files in the book's source folder triggers multiple rebuilds when using mdbook serve. The amount of rebuilds is not constant, I've seen it vary from 2 to over 20 times. Editing markdown files triggers a single rebuild.

Steps

  1. cd $(mktemp -d)
  2. mdbook init </dev/null
  3. echo "export let lorem = 'ipsum';" > src/test.ts
  4. echo -e '```\n{{#include test.ts}}\n```' >> src/chapter_1.md
  5. mdbook serve
  6. in a second terminal: touch src/test.ts
terminal showing over a dozen rebuilds

Possible Solution(s)

Switching notify from macos_fsevent to macos_kqueue seems to fix the issue, triggering only a single rebuild whenever the src/test.ts file changes.

Notes

This happens on an APFS drive on macOS. It doesn't happen on ext4 in a linux VM.

I'm not sure why this happens. A simple test using the following code doesn't trigger the multitude of events, leading me to think the cause lies within mdbook and not in notify.

use std::{path::Path, thread::sleep, time::Duration};

use notify::RecursiveMode;

fn main() {
    let mut debouncer =
        notify_debouncer_mini::new_debouncer(Duration::from_secs(1), None, |event| {
            println!("event {:#?}", event);
        })
        .unwrap();

    let watcher = debouncer.watcher();

    watcher
        .watch(Path::new("."), RecursiveMode::Recursive)
        .unwrap();

    loop {
        sleep(Duration::from_millis(500));
    }
}

Version

mdbook v0.4.32 (also happens on v0.4.31, earlier versions not tested)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: A bug, incorrect or unintended behaviorCommand-watchCommand: watchE-Help-wantedExperience: Help Needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions