Unable to load the Python WEBC because of WasiEnvBuilder preopening behaviour #3686
Labels
bug
Something isn't working
📦 lib-vfs
About wasmer-vfs
📦 lib-wasi
About wasmer-wasi
priority-medium
Medium priority issue
Milestone
Describe the bug
There seems to be an inconsistency between the way
wasmer_wasi::WasiEnvBuilder
's preopened directories work and the paths actually used by theWebcFileSystem
(it might also happen for otherFileSystem
s - I haven't checked).The issue is:
WebcFileSystem
gives you absolute paths when traversing directory trees withFileSystem::read_dir()
andDirEntry
'spath
fieldWasiEnvBuilder
seems to expect you to preopen directories from aWebcFileSystem
using paths that don't have the leading slashWasiEnvBuilder
, especially when filesystem composition comes into play (e.g. mounting and overlays)Steps to reproduce
For consistency, everything is done using the python-0.1.0.wasmer binary and the latest
master
(1fe1e51).First, we start off with some boilerplate to run our "experiment".
Boilerplate
We can use the
WebcFileSystem::top_level_dirs()
function to get the list of top-level directories it thinks we should pre-open.Running the code will show the Python prompt as expected. You can also see it print paths without the leading
/
.Now, let's switch to the more generic method based on
FileSystem::read_dir()
.You'll see that we now print absolute paths and Python will crash because it can't find its standard library.
To make things worse, if you use a
wasmer_vfs::mem_fs::FileSystem
that has directories from awasmer_vfs::host_fs::FileSystem
mounted, using absolute paths to preopen those directories will give the instance access to those directories as expected.Mounting a
WebcFileSystem
onto awasmer_vfs::mem_fs::FileSystem
seems to be broken here. When you use relative paths fromtop_level_dirs()
you'll get awasi filesystem creation error: Could not get metadata for file "lib": fd not a directory
error. However, turning them into absolute paths (e.g. by doingPath::new("/").join(path)
for each path) won't do anything and you'll get the now-familiar fatal Python error 🙃Expected behavior
I'm not really sure.
I think I would expect
WasiEnvBuilder::add_preopen_dir()
to require absolute paths when the underlying filesystem does operations with absolute paths (e.g.WebcFileSystem
), and allow relative paths (e.g../blah
) when the underlying filesystem operations can work with relative paths (e.g.wasmer_vfs::host_fs::FileSystem
).Actual behavior
See above.
Additional context
This was one of the many rabbit-holes I went down as part of #3650 while trying to troubleshoot complex filesystem configurations.
This bug interacts poorly with #3685 because the
FileSystem::read_dir()
method won't even give you valid paths to preopen.The text was updated successfully, but these errors were encountered: