network reads hang on NixOS
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))
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.
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
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
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")
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
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>
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? :)
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
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
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.
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>)
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?
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
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.
Unfortunately I still can't reproduce on x86_64 Debian with kernel 5.7.17, this appears to be NixOS-specific.
One more thing, can you check:
echo test | chibi-scheme -b -mchibi.io -p'(read-line)'
looks fine
echo test | chibi-scheme -b -mchibi.io -p'(read-line)'
"test"
Better test:
(sleep 3; echo test) | chibi-scheme -b -mchibi.io -p'(read-line)'
looks ok.
(sleep 3; echo test) | chibi-scheme -b -mchibi.io -p'(read-line)'
"test"
OK, then it seems specific to network ports.
LD_LIBRARY_PATH
On nixos, I've had to do LD_LIBRARY_PATH=./ ./chibi-scheme [.....]