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

First run of template project fails with WatchfilesRustInternalError #2785

Closed
bertbarabas opened this issue Mar 5, 2024 · 6 comments · Fixed by #2986
Closed

First run of template project fails with WatchfilesRustInternalError #2785

bertbarabas opened this issue Mar 5, 2024 · 6 comments · Fixed by #2986
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@bertbarabas
Copy link

Describe the bug
WatchfilesRustInternalError exception occurs immediately after the first init/run of the sidebar template.
Exception does not occur on subsequent runs
The exception doesn't stop the app from working. I.e. I can view the app at http://localhost:3000/

To Reproduce
Steps to reproduce the behavior:

  • on a brand new folder
  • install reflex
  • reflex init (and pick sidebar template)
  • reflex run
    EXCEPTION:
  • _rust_notify.WatchfilesRustInternalError: error in underlying watcher: IO error for operation on /home/bert_barabas/reflexapp/.web/nocompile: No such file or directory (os error 2) about ["/home/bert_barabas/reflexapp/.web/nocompile"]

Expected behavior
No exception

Screenshots
If applicable, add screenshots to help explain your problem.

Specifics (please complete the following information):

  • Python Version: 3.12.1
  • Reflex Version: v0.4.3
  • OS: WSL on Windows 11 (Ubuntu 22.04.4 LTS (GNU/Linux 5.15.133.1-microsoft-standard-WSL2 x86_64)
  • Browser (Optional):

Additional context
Exception Stack.txt

Add any other context about the problem here.

@picklelo
Copy link
Contributor

picklelo commented Mar 5, 2024

Thanks for reporting - so running it again solves the issue?

Seems like some misconfiguration in our uvicorn on Windows - we shouldn't be watching the .web folder, only the main app folder for reloads...

Perhaps we need to explicitly set the watch dir. If anyone has any ideas, would welcome a fix here

@picklelo picklelo added bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed labels Mar 5, 2024
@bertbarabas
Copy link
Author

Thanks for reporting - so running it again solves the issue?

Correct, the exception only happens on the first "Reflex run".

@bertbarabas
Copy link
Author

Just saw the exception happen again but this time after it had been running a while. So it looks like while this exception happens every time when executing "reflex run" for the very first time on a project, it can also very rarely happen in other cases.

@tsdaemon
Copy link

tsdaemon commented Aug 20, 2024

Weird, but I am having the same error quite often on the latest version (0.5.9):

_rust_notify.WatchfilesRustInternalError: error in underlying watcher: IO error for operation on /home/tsdaemon/ascension/knw/.web/nocompile: No such file or directory (os error 2) about ["/home/tsdaemon/ascension/knw/.web/nocompile"]

@tsdaemon
Copy link

tsdaemon commented Aug 20, 2024

Ok, its not exactly the reflex problem. It can only be solved in uvicorn. See the class definition there:

class WatchFilesReload(BaseReload):
    def __init__(
        self,
        config: Config,
        target: Callable[[list[socket] | None], None],
        sockets: list[socket],
    ) -> None:
        super().__init__(config, target, sockets)
        self.reloader_name = "WatchFiles"
        self.reload_dirs = []
        for directory in config.reload_dirs:
            if Path.cwd() not in directory.parents:
                self.reload_dirs.append(directory)
        if Path.cwd() not in self.reload_dirs:
            self.reload_dirs.append(Path.cwd())

        self.watch_filter = FileFilter(config)
        import pdb

        pdb.set_trace()
        self.watcher = watch(
            *self.reload_dirs,
            watch_filter=None,
            stop_event=self.should_exit,
            # using yield_on_timeout here mostly to make sure tests don't
            # hang forever, won't affect the class's behavior
            yield_on_timeout=True,
        )

    def should_restart(self) -> list[Path] | None:
        self.pause()

        changes = next(self.watcher)
        if changes:
            unique_paths = {Path(c[1]) for c in changes}
            return [p for p in unique_paths if self.watch_filter(p)]
        return None

Even if you set excluded folders, it does not exclude them from watcher: it just ignores them. So if watcher fails, it fails. And for some reason it watches all files in the directory, even if you told it only to watch the code folder. It quite implicit, and bad approach IMHO.

@tsdaemon
Copy link

tsdaemon commented Aug 20, 2024

The problem is listed in uvicorn repository: encode/uvicorn#1785

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants