mthom / scryer-prolog

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

crash when communicating via STDIN/STDOUT #1439

Open peschue opened 2 years ago

peschue commented 2 years ago

Discussed in https://github.com/mthom/scryer-prolog/discussions/1413

I encountered a crash when communicating without a TTY via STDIN/STDOUT.

I have created a minimal package for reproducing the problem: reproduce.tar.gz

When you run

$ ./docker-build.sh
$ ./docker-reproduce.sh

this will build a docker container based on the scryer-prolog container plus python3 and run the reproduce.py script and cause the following messages

consulting file foo.pl
reading 1
read '   true.\n'
sending query 'foo(X).'
reading 2
thread 'main' panicked at 'failed to enable raw mode: IoError(Os { code: 25, kind: Other, message: "Inappropriate ioctl for device" })', src/prolog/machine/system_calls.rs:48:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
read '   X = x'

The script consults a file, which yields "true." followed by posing a query "foo(X)." and while reading the query result the problem happens.

I think scryer-prolog tries to do something that can only be done with a TTY because the script tries to read until the end of output.

Unfortunatley I was not able to reproduce this just on the shell, because it requires waiting for output before sending additional input.

phmarek commented 2 years ago

JFI, here's a small testcase:

$ cat | scryer-prolog -f --no-add-history | cat
[user].
comp(1).
comp(2).
end_of_file.
comp(W).

Pressing Enter on the last line will break 168d1c578909dc143ba52dbed661c36e76b12b36 (from https://hydra.nixos.org/build/186250071#tabs-summary) right after the first answer:

   W = 1thread 'main' panicked at 'failed to enable raw mode: IoError(Os { code: 25, kind: Uncategorized, message: "Inappropriate ioctl for device" })', src/machine/system_calls.rs:82:23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I've already found #739 and cl-psoatransrun, will take a look at them now.