chibi-scheme icon indicating copy to clipboard operation
chibi-scheme copied to clipboard

network reads hang on NixOS

Open ghost opened this issue 3 years ago • 21 comments

sexp_load(ctx, "file.ss", NULL) hangs if file.ss contains http-get from (chibi net http)


callme.c

/* gcc -Wall callme.c -o callme pkg-config chibi-scheme --cflags --libs

  • ./callme */ #include <stdio.h> #include <chibi/eval.h>

int main() { sexp ctx; ctx = sexp_make_eval_context(NULL, NULL, NULL, 0, 0); sexp_load_standard_env(ctx, NULL, SEXP_SEVEN); sexp_load_standard_ports(ctx, NULL, stdin, stdout, stderr, 0);

sexp_gc_var1(file_path); sexp_gc_preserve1(ctx, file_path);

file_path = sexp_c_string(ctx, "callme.ss", -1); sexp_load(ctx, file_path, NULL);

sexp_eval_string(ctx, "(say-hello)", -1, NULL);

sexp_gc_release1(ctx); sexp_destroy_context(ctx); }

callme.ss

(define (say-hello) (display "Hello World from Scheme to C with <3!") (newline))

(import (chibi net http)) (import (chibi io))

;; the following lines cause problem (define url "http://www.example.com") (define p (http-get url)) (define s (port->string p))

ghost avatar Mar 21 '21 01:03 ghost

Can you verify if just running chibi-scheme callme.ss works?

What platform are you on? I've tried both the Scheme file and the C file and they both work for me on Linux.

ashinn avatar Mar 21 '21 02:03 ashinn

chibi-scheme callme.ss also hangs. This is on Linux.


uname -a Linux uf 5.4.85 #1-NixOS SMP Mon Dec 21 12:27:07 UTC 2020 x86_64 GNU/Linux

ghost avatar Mar 21 '21 16:03 ghost

Is this with 0.9.1 or HEAD?

Can you try tracing:

chibi-scheme -tchibi.io.read-string -tchibi.net.http.http-get callme.ss

ashinn avatar Mar 22 '21 04:03 ashinn

0.9.1. Tracing shows > (http-get <url>) then hangs


chibi-scheme -tchibi.io.read-string -tchibi.net.http.http-get callme.ss

(http-get "http://www.example.com")

ghost avatar Mar 22 '21 06:03 ghost

Hmmm... tough to debug when I can't reproduce. You can continue tracing methods within the http implementation:

-tchibi.net.http.{http-call-method,http-send-body,http-parse-response} -tchibi.mime.mime-headers->list

ashinn avatar Mar 22 '21 10:03 ashinn

a bit more info


$ chibi-scheme -tchibi.net.http.{http-call-method,http-send-body,http-parse-response} -tchibi.mime.mime-headers->list callme.ss

couldn't find binding to trace: mime-headers- in (module-env (load-module '(chibi mime))) > (http-call-method GET "http://api.call-cc.org" () #f 10) | > (http-send-body () #f #<Output-Port 139846270462592>) | #<undef>

ghost avatar Mar 23 '21 02:03 ghost

Oh, you'll need to quote the >:

-t'chibi.mim.mime-headers->list'

And just for a sanity check, you don't have a firewall blocking example.com do you? :)

ashinn avatar Mar 23 '21 02:03 ashinn

same thing with http://synthcode.com. C-c C-c out of it because it hangs.


chibi-scheme -tchibi.net.http.{http-call-method,http-send-body,http-parse-response} -t'chibi.mime.mime-headers->list' callme.ss

> (http-call-method GET "http://synthcode.com" () #f 10) | > (http-send-body () #f #<Output-Port 139744227197312>) | #<undef> C-c C-c

curl http://synthcode.com | wc -l

91

ghost avatar Mar 23 '21 02:03 ghost

For the record, HEAD does not run on my machine.

root@delllaptop:~# chibi-scheme 
chibi-scheme: error while loading shared libraries: libchibi-scheme.so.0: cannot open shared object file: No such file or directory

ghost avatar Mar 23 '21 02:03 ghost

You need to either install chibi or specify the LD_LIBRARY_PATH to run.

Try -tchibi.io.%read-line -tchibi.io.%%read-line, it looks like it's hanging there.

ashinn avatar Mar 23 '21 03:03 ashinn

think so, hangs at (read-line 8192 ....)


$ chibi-scheme -tchibi.io.%read-line -t'chibi.io.%%read-line' callme.ss > (%read-line 8192 #<Input-Port 140323032763552>)

ghost avatar Mar 23 '21 04:03 ghost

So the question now becomes whether there was a problem with the request such that the response never comes, or is the read-line stuck for some reason? Can you try running again with strace and sharing the tail of the output?

ashinn avatar Mar 24 '21 01:03 ashinn

maybe this makes sense, there's a bit more: https://paste.debian.net/1190749/


fcntl(3, F_SETFL, O_RDONLY|O_LARGEFILE) = 0 fcntl(3, F_SETFL, O_RDONLY|O_NONBLOCK|O_LARGEFILE) = 0 socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0) = 4 connect(4, {sa_family=AF_UNIX, sun_path="/var/run/nscd/socket"}, 110) = 0 sendto(4, "\2\0\0\0\r\0\0\0\6\0\0\0hosts\0", 18, MSG_NOSIGNAL, NULL, 0) = 18 poll([{fd=4, events=POLLIN|POLLERR|POLLHUP}], 1, 5000) = 1 ([{fd=4, revents=POLLIN}]) recvmsg(4, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="hosts\0", iov_len=6}, {iov_base="\310O\3\0\0\0\0\0", iov_len=8}], msg_iovlen=2, msg_control=[{cmsg_len=20, cmsg_level=SOL_SOCKET, cmsg_type=SCM_RIGHTS, cmsg_data=[5]}], msg_controllen=20, msg_flags=MSG_CMSG_CLOEXEC}, MSG_CMSG_CLOEXEC) = 14 mmap(NULL, 217032, PROT_READ, MAP_SHARED, 5, 0) = 0x7f72230e7000 close(5) = 0 close(4) = 0 socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) = 4 connect(4, {sa_family=AF_INET, sin_port=htons(80), sin_addr=inet_addr("69.164.211.140")}, 16) = 0 fcntl(4, F_GETFL) = 0x2 (flags O_RDWR) fcntl(4, F_SETFL, O_RDWR|O_NONBLOCK) = 0 write(4, "GET / HTTP/1.0\r\nHost: synthcode."..., 77) = 77 read(4, 0x7f7223743914, 4092) = -1 EAGAIN (Resource temporarily unavailable) select(1, [], NULL, NULL, NULL C-c C-c) = ? ERESTARTNOHAND (To be restarted if no handler) strace: Process 27187 detached

ghost avatar Mar 24 '21 02:03 ghost

Thanks, we're getting somewhere! I can see your requests in my logs and they return normally.

strace on my own machine shows only calls to poll, not select, and somehow you're calling select on an empty set of file descriptors with no timeouts, so of course that will hang.

I'm running on kernel 4.15, let me see if I can get access to a 5.x box.

ashinn avatar Mar 24 '21 06:03 ashinn

Unfortunately I still can't reproduce on x86_64 Debian with kernel 5.7.17, this appears to be NixOS-specific.

ashinn avatar Mar 24 '21 09:03 ashinn

One more thing, can you check:

echo test | chibi-scheme -b -mchibi.io -p'(read-line)'

ashinn avatar Mar 25 '21 14:03 ashinn

looks fine

echo test | chibi-scheme -b -mchibi.io -p'(read-line)' "test"

ghost avatar Mar 26 '21 00:03 ghost

Better test:

(sleep 3; echo test) | chibi-scheme -b -mchibi.io -p'(read-line)'

ashinn avatar Mar 26 '21 00:03 ashinn

looks ok.

(sleep 3; echo test) | chibi-scheme -b -mchibi.io -p'(read-line)' "test"

ghost avatar Mar 26 '21 02:03 ghost

OK, then it seems specific to network ports.

ashinn avatar Mar 26 '21 02:03 ashinn

LD_LIBRARY_PATH

On nixos, I've had to do LD_LIBRARY_PATH=./ ./chibi-scheme [.....]

husnoo avatar Dec 07 '22 22:12 husnoo