ocaml / dune

A composable build system for OCaml.
https://dune.build/
MIT License
1.6k stars 397 forks source link

Internal error: EACCES exception uncaught, opinions on how to catch it? #5468

Open hyphenrf opened 2 years ago

hyphenrf commented 2 years ago

XDG_RUNTIME_DIR is set to a custom directory (/var/run/...) that doesn't exist, and which has a parent dir that the user has no privs for.. but dune doesn't fallback or catch that exception.

invoking dune build -w results in the following internal error:

/-----------------------------------------------------------------------
| Internal error: Uncaught exception.
| Unix.Unix_error(Unix.EACCES, "mkdir", "/var/run/user/<username here>")
| Raised by primitive operation at Stdune__fpath.mkdir in file "otherlibs/stdune/fpath.ml", line 12, characters 4-24
| Called from Stdune__fpath.mkdir_p in file "otherlibs/stdune/fpath.ml", line 23, characters 8-24
| Called from Stdune__fpath.mkdir_p in file "otherlibs/stdune/fpath.ml", line 34, characters 12-33
| Called from Stdune__fpath.mkdir_p in file "otherlibs/stdune/fpath.ml", line 34, characters 12-33
| Called from Dune_rpc_impl__run.run.(fun) in file "src/dune_rpc_impl/run.ml", line 86, characters 23-60
| Called from Fiber.Scheduler.exec in file "src/fiber/fiber.ml", line 854, characters 10-13
\-----------------------------------------------------------------------

but the watch mode blocks with success still. Invoking without -w flag doesn't result in the same problem.

A possible patch I could start working on is one which adds a new error case for lack of perms, but how would the exception best be handled anyway? Should we panic and break execution? should we silently fallback to a default runtime dir?

bg info:

rgrinberg commented 2 years ago

I think the best that we can do here is gracefully shut down the rpc server and warn the user that a writeable XDG_RUNTIME_DIR must be provided

hyphenrf commented 2 years ago

would you like me to work on that? I haven't touched this codebase before, but I'd love to contribute.

hyphenrf commented 2 years ago

Hey so I made this little thing (#5478), feel free to check it out whenever

lukstafi commented 9 months ago

I just started having this error logged, under WSL, but it seems to not affect functionality:

Uncaught RPC Error
Unix.Unix_error(Unix.EACCES, "mkdir",
"/mnt/wslg/runtime-dir/dune/rpc")
backtrace:
Raised by primitive operation at Stdune__Fpath.mkdir in file
"otherlibs/stdune/src/fpath.ml", line 11, characters 4-24
Called from Stdune__Fpath.mkdir_p in file "otherlibs/stdune/src/fpath.ml",
line 23, characters 8-24
Called from Dune_rpc_impl__Server.Run.run.run.(fun) in file
"src/dune_rpc_impl/server.ml", line 97, characters 45-82
Called from Dune_rpc_impl__Server.Run.run.run.(fun) in file
"src/dune_rpc_impl/server.ml", line 78, characters 12-999
Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml",
line 76, characters 8-11

Success, waiting for filesystem changes...
Alizter commented 9 months ago

@lukstafi Which version of WSL are you using? IIRC 1 has some issues with unix system calls, but 2 usually is smooth.

lukstafi commented 9 months ago

@lukstafi Which version of WSL are you using? IIRC 1 has some issues with unix system calls, but 2 usually is smooth.

It is WSL 2. It is a newly-appearing issue. It reproduces on different switches (5.1.0, 4.13.1, updated). Interestingly, I see the problem with Ubuntu 23.10, but not with Debian Trixie! (Feel free to ask me to test more Linuxes on WSL 2.) Both have opam 2.1.5 and dune 3.12.1.

lukstafi commented 9 months ago

I see the problem with Ubuntu 23.10, but not with Debian Trixie!

Found it! The above is mis-diagnosed. I was missing switch-relative env-vars as per eval $(opam env).

Update: this was probably a wrong conclusion, see the next comment.

lukstafi commented 9 months ago

What I currently observe is: I consistently get Uncaught RPC Error when I run dune in watch mode: dune build -w, but not with a single run: dune build. That confused my reporting before.

Alizter commented 9 months ago

@lukstafi Could you share the exact error? Is it the same as the original issue?

lukstafi commented 9 months ago

Is it the same as the original issue?

Quick answer: I started with a drive-by comment since googling for the error raised led me here. I have not originally read through the issue and proposed solution, but quickly checking things shows that it is indeed related.

lukstafi@DESKTOP-6RRUNR4:~$ echo $XDG_RUNTIME_DIR
/mnt/wslg/runtime-dir
lukstafi@DESKTOP-6RRUNR4:~$ ls -l /mnt/wslg/runtime-dir
ls: cannot open directory '/mnt/wslg/runtime-dir': Permission denied
lukstafi@DESKTOP-6RRUNR4:~$ ls -l /mnt/wslg
total 56
drwxrwxrwx  2 root   root      40 Dec  6 08:36 dumps
-rw-------  1 ubuntu ubuntu  1371 Dec  6 08:36 pulseaudio.log
drwx------  4 ubuntu ubuntu   120 Dec  6 08:36 runtime-dir
...
Alizter commented 9 months ago

@lukstafi It seems like an incorrect configuration to have a read only one. What are your OS details? I'm thinking it might be a OS bug to have XDG_RUNTIME_DIR read only, as it should be owned when created during login by the user.

In any case, we need to improve the error message in Dune. We could also provide a workaround temporary directory in _build/.

lukstafi commented 9 months ago

Yes, I'm not worrying, it's not a "supported" WSL Linux distribution, I installed it from a docker image. I confirmed that things work with a WSL Linux distro from the Microsoft store (i.e. available via the WSL CLI).