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

问题描述 投票:3回答:4

我正在开发一个Spring Boot 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答案没有用。

spring spring-boot docker swi-prolog jpl
4个回答
1
投票

我想我会尝试“消费”这个词。例如

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

1
投票

这不是一个直接的答案,因为它提出了一种不同的方法,但是很长一段时间我都在运行一个设置,我编写的C ++程序会像你使用Spring Boot一样包装SWI-Prolog,并且很难添加功能。 /保持。大约一年前,我采用了一种完全不同的方法,我在SWI-Prolog中添加了一个MQTT插件,因此我的Prolog代码可以连续运行并响应并发送MQTT消息。所以现在Prolog可以与各种语言的其他模块(主要是Java)进行互操作,但是一切都在自己的流程中运行。这对我来说效果更好,我已经在Docker容器中运行了所有东西 - 包括MQTT代理。我并没有建议MQTT(虽然我喜欢它),只是考虑让Java和Prolog不那么紧密耦合的方法。


0
投票

最有可能的原因是它第二次失败是因为你再次打电话给JPL.init()。它应该只被调用一次。


0
投票

最后这是JPL包的一个bug。在联系SWI-Prolog开发人员之后,他们修补了SWI-Prolog Git的修复程序,现在错误消失了!

正确的配置,以便Docker容器能够理解JPL在这个链接中找到:Github : env.sh

© www.soinside.com 2019 - 2024. All rights reserved.