Pytest segfault failure issue

Hi. I was writing unit tests in orekit-python which I wanted to run using pytest, and I encountered a strange error. When I tried to run the test

import orekit

from orekit.pyhelpers import setup_orekit_curdir

def test_function():
    # Test code here

and run the test from the command line (linux) using:

python -m pytest test    #"test" is name of test directory

I got a segfault error. However, when I switched up the code to:

import orekit
jvm = orekit.initVM()

from orekit.pyhelpers import setup_orekit_curdir

def test_function():
    # Test code here

This test worked without incident. Has anyone ever encountered a similar error? Could this be a bug with the code that calls the orekit JVM? Thank you in advance for your help.

I’m running into segmentation fault issues when using Orekit as well, though, not while running tests. It doesn’t always happen, however, and when it does happen it doesn’t seem to always be occurring at the same location either.

# An irrecoverable stack overflow has occurred.
# A fatal error has been detected by the Java Runtime Environment:
#  SIGSEGV (0xb) at pc=0x0000000104e81ab0, pid=8553, tid=0x0000000000000103
# JRE version: OpenJDK Runtime Environment (Zulu (8.0_382-b05) (build 1.8.0_382-b05)
# Java VM: OpenJDK 64-Bit Server VM (25.382-b05 mixed mode bsd-aarch64 compressed oops)
# Problematic frame:
# C  [python3.11+0xa5ab0]  _Py_dict_lookup+0x44
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
# An error report file with more information is saved as:
# /Users/natalie.tipton/repos/orbit-determination/hs_err_pid8553.log
# If you would like to submit a bug report, please visit:
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.

Only thoughts we’ve come up with would be that Orekit may be spinning off threads in the background and the JVM thread isn’t being attached to them. Any guidance or other ideas?

--------------- P R O C E S S ---------------
Java Threads: ( => current thread )
0x000000012393e000 JavaThread “Service Thread” daemon [_thread_blocked, id=19459, stack(0x0000000342804000,0x0000000342a07000)]
0x000000012476f800 JavaThread “C1 CompilerThread3” daemon [_thread_blocked, id=19971, stack(0x0000000341d3c000,0x0000000341f3f000)]
0x0000000124409800 JavaThread “C2 CompilerThread2” daemon [_thread_blocked, id=20483, stack(0x0000000341b30000,0x0000000341d33000)]
0x00000001238f6000 JavaThread “C2 CompilerThread1” daemon [_thread_blocked, id=17667, stack(0x0000000341924000,0x0000000341b27000)]
0x0000000123922000 JavaThread “C2 CompilerThread0” daemon [_thread_blocked, id=20739, stack(0x0000000341718000,0x000000034191b000)]
0x0000000123920800 JavaThread “Signal Dispatcher” daemon [_thread_blocked, id=17155, stack(0x0000000339414000,0x0000000339617000)]
0x0000000112c13000 JavaThread “Finalizer” daemon [_thread_blocked, id=14595, stack(0x000000033917c000,0x000000033937f000)]
0x0000000112c10000 JavaThread “Reference Handler” daemon [_thread_blocked, id=12035, stack(0x0000000338f70000,0x0000000339173000)]
=>0x000000012476c000 JavaThread “main” [_thread_in_native, id=259, stack(0x0000000169024000,0x000000016b024000)]
Other Threads:
0x0000000112c09000 VMThread [stack: 0x0000000338d64000,0x0000000338f67000] [id=11779]
0x000000012393f000 WatcherThread [stack: 0x0000000342a10000,0x0000000342c13000] [id=19203]

Hi @baubin

It is hard to say without a test that can be run and fails, your initial test should work stand-alone.

What it seems is that something is using multi-threading, either in pytest or in your code and in that case you need to attach each thread to the jvm with the jvm.attachCurrentThread(). See Python wrapper and orekit.initVM()

What is a known bug is the combination of pycharm’s debug feature that asynchronously gets values of object, that is often crashing orekit, we have not been able to track down the source of this. This can be mitigated by setting the Pycharm loading to on-demand.

@nattip hard to say but seems like your stack is overflown. Try to increase the JVM max stack memory allocation, the vmargs can be set through the .initVM(vmargs=str ) where str is jvm start parameters. I think the stack is -XmxZZ for stack but please goolge. Likely something isn’t right if you run out of stack.