Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker container with SWI-Prolog terminated with fatal error

Im developing a Spring Boot Web Application, using SWI-Prolog's JPL interface to call Prolog from Java. In development mode everything runs OK. When I deploy it to Docker the first call on JPL through API, runs fine. When I try to call JPL again, JVM crashes.

I use LD_PRELOAD to point to libswipl.so

SWI_HOME_DIR is set also.

LD_LIBRARY_PATH is set to point to libjvm.so

My Controller function:

@PostMapping("/rules/testAPI/")
@Timed
public List<String> insertRule() {
    String use_module_http = "use_module(library(http/http_open)).";
    JPL.init();
    
    Query q1 = new Query(use_module_http);
    if (!q1.hasNext()) {
        System.out.println("Failed to load HTTP Module");
    } else {
        System.out.println("Succeeded to load HTTP Module");
    }

    return null;
}

Console output

1st Call

Succeeded to load HTTP Module

2nd Call

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f31705294b2, pid=16, tid=0x00007f30d2eee700
#
# JRE version: OpenJDK Runtime Environment (8.0_191-b12) (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
# Java VM: OpenJDK 64-Bit Server VM (25.191-b12 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libswipl.so+0xb34b2]  PL_thread_attach_engine+0xe2
#
# Core dump written. Default location: //core or core.16
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

I uploaded the error log file in pastebin. click here

Has anyone faced the same problem? Is there a solution about this?

Note that, I also checked it also with oracle-java-8 but the same error occurs.

UPDATE:

@CapelliC answer didn't work.

like image 504
Antifa Avatar asked Oct 24 '25 00:10

Antifa


1 Answers

I think I would try to 'consume' the term. For instance

Query q1 = new Query(use_module_http);
if (!q1.hasNext()) {
    System.out.println("Failed to load HTTP Module");
} else {
    System.out.println("Succeeded to load HTTP Module:"+q1.next().toString());
    // remember q1.close() if there could be multiple soultions
}

or better

if ((new Query(use_module_http)).oneSolution() == null) ...

or still better

if ((new Query(use_module_http)).hasSolution() == false) ...
like image 80
CapelliC Avatar answered Oct 26 '25 16:10

CapelliC