Failed to consult pl file

I’m using: SWI-Prolog version 9.0.4 for x86_64-linux

In the Java web project, the third request to consult pl file threw the following error:

  ../src/pl-thread.c:8079: stack_avail___LD: Assertion failed: here > info->c_stack_base
  C-stack trace labeled "assert_fail":
    [0] save_backtrace() at /downloads/swipl/build/../src/os/pl-cstack.c:337 [0x7fe8a79eb2da]
    [1] __assert_fail() at /downloads/swipl/build/../src/pl-assert.c:105 [0x7fe8a79b437a]
    [2] pl_functor_table_in_use() at /downloads/swipl/build/../src/pl-thread.c:7866 (discriminator 1) [0x7fe8a79a21f7]
    [3] require_c_stack___LD() at /downloads/swipl/build/../src/pl-thread.c:8096 [0x7fe8a79a21c2]
    [4] callProlog() at /downloads/swipl/build/../src/pl-pro.c:425 [0x7fe8a7a0e55c]
    [5] pl_sig_atomic1_va() at /downloads/swipl/build/../src/pl-pro.c:361 [0x7fe8a7a0e7c4]
    [6] PL_next_solution___LD() at /downloads/swipl/build/../src/pl-vmi.c:4747 [0x7fe8a79f6825]
    [7] Java_org_jpl7_fli_Prolog_next_1solution() at /downloads/swipl/build/../packages/jpl/src/main/c/jpl.c:4188 [0x7fe87c0992a4]
  Prolog stack:
    [16] system:sig_atomic/1 [PC=1 in supervisor]
    [15] system:setup_call_catcher_cleanup/4 [PC=4 in clause 1]
    [11] system:$file_type_extensions/2 [PC=24 in clause 2]
    [10] system:absolute_file_name/3 [PC=56 in clause 2]
    [9] system:$resolve_source_path/3 [PC=54 in clause 1]
    [8] system:$load_file_e/3 [PC=21 in clause 3]
    [7] system:$load_file/3 [PC=12 in clause 1]
    [0] system:$c_call_prolog/0 [PC=0 in top query clause]

  Aborted

My code looks like this:

  @GetMapping("/test/swipl")
  public void testSwipl() {
      new Query("consult", new Term[]{new Atom("/data/pl/test.pl")}).hasSolution();
  }

It seems these two lines make sense and indicate you are running out of C stack. Or, looking at the assertion failure in stack_avail(), something weird is going on with the C stack. Surely it indeed grows down on X86_64 AFAIK.

It could really be running out of stack or the C stack availability checks are not properly working with JPL. It should not be too hard to figure that out using gdb and/or some print statements in the code trying to verify the C stack availability. If you want others to do that, please make complete source code available, so we can simply run your program and observe its behavior.

/data/pl/test.pl

  items('test').

If that is supposed to be the code to reproduce, I’m afraid this won’t do. What matters most is probably the Java code and how exactly this uses Prolog. With code, I mean something we can run to reproduce your problem. I think that means the Java code and Prolog code including instructions on how to get it running and reproduce the crash. This looks like something where the details matter.

The complete code has been uploaded to Google Cloud Drive:

https://drive.google.com/file/d/1fFnvXxowkk5ocoHcpNSzamE7wreH7FqF/view?usp=sharing

So far, so good. How do I use this? Don’t expect any knowledge about Java infrastructure on my side.

This is the packaged jar file

https://drive.google.com/file/d/1WRwRpDooUJ06deuOD8O5M-hQmDBGOWRw/view?usp=sharing

Debian 11.7, You need to first configure the Java environment, copy the test.pl file to /data/pl directory, run jar

java -jar swipl-test-1.0-SNAPSHOT.jar

and access it in the browser

http://ip:60001/test/swipl 

The error will occur on the third request.

Thanks. That works and reproduced. Turns out that C-stack protection didn’t work when Prolog engines hop between threads as they do with JPL (and some other not-so-common scenarios). Required some redesign :frowning: Seems to work fine after commit 15f8cfd92949552b4e16c99723fc53e9fad7a3be to swipl-devel.git.

1 Like

Thank you, it can now be used normally