odin-http icon indicating copy to clipboard operation
odin-http copied to clipboard

Running on Termux asserts

Open 0dminnimda opened this issue 1 year ago • 8 comments

Tried to run it on termux proot-distro and got such kinds of errors:

/data/data/com.termux/files/home/.../odin-http/server.odin(141:2) runtime assertion: errno == os.ERROR_NONE
/data/data/com.termux/files/home/.../odin-http/nbio/_io_uring/os.odin(94:2) runtime assertion: (params.features & IORING_FEAT_SINGLE_MMAP) != 0

0dminnimda avatar Oct 29 '24 14:10 0dminnimda

It probably doesn't support IO Uring.

It's in the plans to have an alternative backend to choose from but that's a bit away.

laytan avatar Oct 29 '24 17:10 laytan

It appears to be supported

$ sudo grep io_uring_setup /proc/kallsyms
0000000000000000 T __arm64_sys_io_uring_setup
0000000000000000 t __arm64_sys_io_uring_setup.cfi_jt
0000000000000000 d _eil_addr___arm64_sys_io_uring_setup

But

#include <errno.h>
#include <linux/io_uring.h>
#include <stddef.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <stdio.h>

int main(int argc, char **argv) {
  if (syscall(__NR_io_uring_register, 0, IORING_UNREGISTER_BUFFERS, NULL, 0) && errno == ENOSYS) {
    printf("No io_uring\n");
  } else {
    printf("Ye io_uring\n");
  }
}

is not accessible from proot-distro

[root@localhost ...]# ./test_io_uring.o
No io_uring

while not working in usual mode, and working in sudo

$ ./test_io_uring.o
Bad system call
$ sudo ./test_io_uring.o
Ye io_uring

Oh how fun it is working from android ;)

0dminnimda avatar Oct 29 '24 21:10 0dminnimda

Aha, so it doesn't assert when running in sudo then?

laytan avatar Oct 30 '24 12:10 laytan

Unfortunately I cannot check for this right now. I cannot get odin to compile on regular termux, because its libllvm is version 19, which is not supported by odin. I didn't have enough time to look into the underlying reason/hack it.

0dminnimda avatar Oct 30 '24 13:10 0dminnimda

After some modifications to the odin, I was able to get this working. The only thing that confused me at first is that the example server does not serve the / which made me first think that the server was not properly running. Second thing is that it's not cancallable with Ctrl-C. That's quite bad to have to go to ps aux to shut down the server immideately. While pressing Ctrl-D will print [2024-11-06 18:07:29] [server.odin:289:_server_thread_shutdown()] shutdown: done but the program remained running for quite some time, finally stopping after about a minute.

But overall looking fowrard to using it.

0dminnimda avatar Nov 06 '24 18:11 0dminnimda

So / and /index serve an html file. Wold be nice to mention that in the readme!

0dminnimda avatar Nov 06 '24 19:11 0dminnimda

What do you mean?

laytan avatar Nov 06 '24 21:11 laytan

Example in the readme serves an html file for /index. So just compiling and running the example can lead to confusion, as the index will error 404

index :: proc(req: ^http.Request, res: ^http.Response) {
	http.respond_file(res, "examples/complete/static/index.html")
}

0dminnimda avatar Nov 06 '24 23:11 0dminnimda