Docker 带有 SWI-Prolog 的容器因致命错误而终止

Docker container with SWI-Prolog terminated with fatal error

我正在开发一个 Spring 引导 Web 应用程序,使用 SWI-Prolog 的 JPL 接口从 Java 调用 Prolog。在开发模式下,一切运行正常。 当我将它部署到 Docker 时,通过 API 对 JPL 的第一次调用运行良好。当我再次尝试调用 JPL 时,JVM 崩溃了。

我用LD_PRELOAD指向libswipl.so

SWI_HOME_DIR也设置了。

LD_LIBRARY_PATH 设置为指向 libjvm.so

我的控制器功能:

@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;
}

控制台输出

第一次通话

Succeeded to load HTTP Module

第二次通话

#
# 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.
#

我在pastebin 上传了错误日志文件。 click here

有人遇到过同样的问题吗?有解决办法吗?

请注意,我也用 oracle-java-8 检查了它,但出现了同样的错误。

更新:

@CapelliC 的回答无效。

我想我会尝试 'consume' 这个词。例如

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
}

或更好

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

或更好

if ((new Query(use_module_http)).hasSolution() == false) ...

不是一个直接的答案,因为它提出了一种不同的方法,但很长一段时间我都在运行设置一个我写的 C++ 程序会像你用 Spring 引导,添加功能非常困难 to/maintain。大约一年前,我采用了一种完全不同的方法,我向 SWI-Prolog 添加了一个 MQTT 插件,这样我的 Prolog 代码就可以 运行 连续响应并发送 MQTT 消息。所以现在 Prolog 可以与多种语言的其他模块进行互操作(主要是 Java),但所有内容 运行 都在其自己的进程中。这对我来说效果更好,我在 Docker 容器中得到了所有 运行ning - 包括 MQTT 代理。我并不是坚定地建议 MQTT(虽然我喜欢它),只是考虑让 Java 和 Prolog 不那么紧密耦合的方法。

第二次失败的原因很可能是因为您再次调用 JPL.init()。它应该只调用一次。

终于是JPL包的bug了。联系 SWI-Prolog 开发人员后,他们修补了 SWI-Prolog Git,现在错误消失了!

正确的配置,让Docker容器能够理解JPL是在这个link中找到的:Github : env.sh