Repository: wasmerio/wasmer (language: rust)

Issue:
WASIX: Directory and Socket closing does not work
### Describe the bug

The `fd_close` syscall fails for both sockets and for directory handles in PHP.

`fd_close()` with a directory fd fails with: `Errno::isdir`
`fd_close()` with a socket fails with: `Errno::access`




Discussion / hints:
We will need a backport of this to the `edge` branch.

The last commit we used before the v6 merge was 

```
 version = "0.35.0"
-source = "git+https://github.com/wasmerio/wasmer?branch=edge#ee7de5f56a554c9c0ab7e13d5a144e722bafd1f1"
+source = "git+https://github.com/wasmerio/wasmer?branch=edge#468068ab7247788dfb32afc2624dcf5bc30f8647"
```

So backport should be on top of `ee7de5f56a554c9c0ab7e13d5a144e722bafd1f1`

Fix patch:
diff --git a/lib/wasix/src/syscalls/wasi/fd_close.rs b/lib/wasix/src/syscalls/wasi/fd_close.rs
index fa05af87887..c07d4ddab04 100644
--- a/lib/wasix/src/syscalls/wasi/fd_close.rs
+++ b/lib/wasix/src/syscalls/wasi/fd_close.rs
@@ -32,7 +32,7 @@ pub fn fd_close(mut ctx: FunctionEnvMut<'_, WasiEnv>, fd: WasiFd) -> Result<Errn
     // does writes in the background, it may miss writes if the file is
     // closed without flushing first. Hence, we flush once here.
     match __asyncify_light(env, None, state.fs.flush(fd))? {
-        Ok(_) | Err(Errno::Io) | Err(Errno::Access) => {}
+        Ok(_) | Err(Errno::Isdir) | Err(Errno::Io) | Err(Errno::Access) => {}
         Err(e) => {
             return Ok(e);
         }


Test patch:
diff --git a/tests/wasix/fd-close/main.c b/tests/wasix/fd-close/main.c
new file mode 100644
index 00000000000..5f63a4f8a21
--- /dev/null
+++ b/tests/wasix/fd-close/main.c
@@ -0,0 +1,36 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <fcntl.h>
+
+int main()
+{
+    int fd = socket(AF_INET, SOCK_STREAM, 0);
+    if (fd < 0)
+    {
+        perror("socket");
+        return 1;
+    }
+
+    if (close(fd) < 0)
+    {
+        perror("socket close");
+        return 1;
+    }
+
+    fd = open("/bin", O_RDONLY | O_DIRECTORY);
+    if (fd < 0)
+    {
+        perror("open dir");
+        return 1;
+    }
+
+    if (close(fd) < 0)
+    {
+        perror("dir close");
+        return 1;
+    }
+
+    return 0;
+}
\ No newline at end of file
diff --git a/tests/wasix/fd-close/run.sh b/tests/wasix/fd-close/run.sh
new file mode 100755
index 00000000000..e336f6fd178
--- /dev/null
+++ b/tests/wasix/fd-close/run.sh
@@ -0,0 +1,3 @@
+set -e
+
+$WASMER -q run main.wasm