astonbitecode / j4rs

Java for Rust
Apache License 2.0
635 stars 35 forks source link

SIGSEGV in tests and in GDB #127

Open AzHicham opened 2 months ago

AzHicham commented 2 months ago

Hello,

First of all thank for this library, it works like a charm. :)

I'm working on a rust wrapper of a java library. I noticed that when I launch cargo test sometimes one or two of my tests are failing because of a SIGSEGV. So I tried many changes on my code but still having casual SIGSEGV (not always the same test ...).

Then I tried to run the debugger, unfortunately dbg catches a SIGSEGV during program startup.... Then to make it more simple I created a sample code to check where this SIGSEGV is coming from. Buy dbg fails immediately catching a SIGSEGV Here are my results:

Cargo.toml

[package]
name = "java-example"
version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = { version = "1" }
j4rs = {version = "0.20", features = []}

main.rs

use j4rs::{JvmBuilder};

fn main() -> Result<(), anyhow::Error> {
    // Create a JVM
    let jvm = JvmBuilder::new().build()?;
    Ok(())
}

Launching the program with dbg in RustRover or with cmd line give me the same results:

╰─ rust-gdb target/debug/java-example                                                       ─╯
GNU gdb (Ubuntu 12.1-0ubuntu1~22.04.2) 12.1
Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from target/debug/java-example...
(gdb) run
Starting program: /home/hazimani/dev/java-example/target/debug/java-example
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[Detaching after vfork from child process 520446]

Program received signal SIGSEGV, Segmentation fault.
0x00007fffe5e5f620 in ?? ()
(gdb) bt
#0  0x00007fffe5e5f620 in ?? ()
#1  0x0000000000000202 in ?? ()
#2  0x00007fffe5e5f714 in ?? ()
#3  0x00007ffff7ad4930 in ?? () from /usr/lib/jvm/java-21-openjdk-amd64/lib/server/libjvm.so
#4  0x00007fffffff7e20 in ?? ()
#5  0x00007ffff760bede in VM_Version::get_processor_features() ()
   from /usr/lib/jvm/java-21-openjdk-amd64/lib/server/libjvm.so
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

image

I don't know if this SIGSEGV when creating a JVM is the same as the one catched during cargo test TBH.

Plus this SIGSEGV seems not to be a problem because when a launch the program I do not have any issue the code works perfectly. It's more a CI issue due to the randomness of this SIGSEGV during cargo test run

Thanks a lot

EDIT: added backtrace

astonbitecode commented 2 months ago

Hi,

Can you please check using the j4rs master instead of the latest release? There are some changes and fixes from fellow contributors that dealt with possible issues during build and could possible affect CIs, especially when caching was enabled.

Thanks

astonbitecode commented 2 weeks ago

Hi @AzHicham , did you have the chance to check the issue using the master?