mthom / scryer-prolog

A modern Prolog implementation written mostly in Rust.
BSD 3-Clause "New" or "Revised" License
2.05k stars 121 forks source link

http_server ; http_open server hangs, no response after pulling some updates #2470

Open Zandrenel opened 3 months ago

Zandrenel commented 3 months ago

I had a http_server I was working on, it was working except its process would get the req then hang if I tried to make a http_open call in the request, the http_open call at the time worked separetely and the http_server worked perfectly fine except in that instance. I tried to update scryer-prolog + my system and since then a simple GET req to / on a http_server hangs and never returns response, same was true locally and tested on a separate computer running windows with a fresh scryer-prolog build.

Example of the steps I can take to recreate:

file contents, test.pl

:- use_module(library(http/http_server)).
:- use_module(library(http/http_open)).
:- use_module(library(charsio)).

server(Port) :-
    http_listen(Port, [
                    get(/, root_handler),
            get(test, root_handler2)
        ]).

root_handler(_Request, Response):-
    write(1),
    http_status_code(Response, 200),
    write(2),
    http_body(Response, text("Hello!")),
    write(3).

root_handler2(_Request, Response):-
    write(1),
    test_get(HTML),
    write(5),
    http_body(Response, text(HTML)),
    write(6).

test_get(Text):-
    write(2),
    http_open("https://github.com/mthom/scryer-prolog", S, [method(get)]),
    write(3),
    get_n_chars(S, 10, Text),
    close(S),
    write(4).

$ scryer-prolog test.pl ?- server(3000). Listening at 0.0.0.0:3000 next sending $ curl localhost:3000 results in no response ever reaching curl and the output

2024-08-07 (19:10:16) get /
123

from prolog, also closing the terminal is impossible unless forcefully

test 2:

?- test_get(X).
234   X = "\n\n\n\n\n\n\n<!D".
?- 

test 3:

?- server(3000).
Listening at 0.0.0.0:3000
2024-08-07 (19:17:25) get /test
12

so in test 1 it just never returns, in 2 it is fine with just the open, in 3 it never gets past the open. at the very least test 1 was working 2 weeks ago before i updated.

aarroyoc commented 3 months ago

I think some dependencies were upgraded this week, which might have lead to that regression.

However I don't think rolling back to an older version is a real fix. I've been working on a plugin interface. Once it's done, this predicates will be implemented using that interface. Current approach requires many moving parts and it's not a good fit.

Zandrenel commented 3 months ago

If there's anything that can be done to assist with that I'd be interested, otherwise that sounds good and I hope that it goes well!