Skip to content

Commit c9d2e0a

Browse files
authored
arcadedb-jvm on Python 3.11: keep jpype1 below 1.8, which crashes the process on Ctrl-C (#537)
jpype1 1.8.0 (2026-11-29) segfaults on CPython 3.11 when an exception that CPython holds without an instance (KeyboardInterrupt from Ctrl-C, StopIteration from next()) goes through JPype: JPPyErr::restore reads the type of a null pointer. CPython 3.12 and later always hold an instance, so they stay on the latest release. tests/test_jpype_bare_exceptions.py runs the case in a child process without timing and fails on 3.11 with 1.8.0.
1 parent 133251b commit c9d2e0a

5 files changed

Lines changed: 95 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ uv add arcadedb-jvm # JVM, for heavy long-running loads
4747

4848
> Old names: `arcadedb-jvm` was formerly `arcadedb-embedded`, and `arcadedb` was formerly `arcadedb-embedded-native` (archived on PyPI). The last `arcadedb-embedded` release, 26.11.1, is a deprecation shim: it installs `arcadedb`, the native build, and warns once at import. It does not install `arcadedb-jvm`.
4949
50-
- Python: `arcadedb` (native) is tested on 3.11 to 3.14 and also installs on 3.15 (`requires-python` is `>=3.11` with no upper bound; the CI runs a subset of the tests on 3.15). `arcadedb-jvm` needs 3.11 to 3.14 (`requires-python` is `>=3.11,<3.15`; its dependency JPype has no 3.15 wheel yet). Each release builds and tests both packages on Python 3.11 to 3.14 on all four platforms below. Between releases, `main` and the nightly run test `arcadedb` on 3.12 and 3.14 on every platform (with a short subset on 3.11, 3.13 and 3.15), and `arcadedb-jvm` on 3.11 to 3.14 on Linux x86-64 and on 3.11 and 3.14 on the other three. A pull request runs Linux x86-64 only, and the other platforms when it carries the label `ci:full` ([CONTRIBUTING](https://github.com/ArcadeData/arcadedb-python/blob/main/CONTRIBUTING.md#what-ci-runs)).
50+
- Python: `arcadedb` (native) is tested on 3.11 to 3.14 and also installs on 3.15 (`requires-python` is `>=3.11` with no upper bound; the CI runs a subset of the tests on 3.15). `arcadedb-jvm` needs 3.11 to 3.14 (`requires-python` is `>=3.11,<3.15`; its dependency JPype has no 3.15 wheel yet). On Python 3.11 it installs JPype below 1.8, because 1.8.0 can crash the process there; with a release up to 26.11.1.post4, run `uv add "jpype1<1.8"` in your project. Each release builds and tests both packages on Python 3.11 to 3.14 on all four platforms below. Between releases, `main` and the nightly run test `arcadedb` on 3.12 and 3.14 on every platform (with a short subset on 3.11, 3.13 and 3.15), and `arcadedb-jvm` on 3.11 to 3.14 on Linux x86-64 and on 3.11 and 3.14 on the other three. A pull request runs Linux x86-64 only, and the other platforms when it carries the label `ci:full` ([CONTRIBUTING](https://github.com/ArcadeData/arcadedb-python/blob/main/CONTRIBUTING.md#what-ci-runs)).
5151
- Linux x86_64 and ARM64, macOS on Apple Silicon, Windows x86_64, for both packages. The Windows wheel of `arcadedb` is the newest.
5252
- Import name: `arcadedb`. Check which package you have with `python -c "import arcadedb; print(arcadedb.__backend__)"`. It prints `native` or `jvm`.
5353
- Optional extras: `arrow`, `pandas`, `polars`, `vector` for `arcadedb-jvm`; `numpy`, `arrow`, `pandas`, `polars` for `arcadedb`.

‎docs/modules/ROOT/pages/installation.adoc‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ NOTE: *First release.* The first release of this layout is 26.11.1, and both pac
3131
// REMOVE WHEN: the old arcadedb-embedded* shims are retired and two releases have shipped with the two-package layout allow-old-name
3232
NOTE: *Old names.* The JVM package was formerly `arcadedb-embedded`. It is now `{jvm-pkg-name}`, the same build. The native package was formerly `arcadedb-embedded-native`. It is now `{native-pkg-name}`, and the old project is archived. The last `arcadedb-embedded` release, 26.11.1, is a shim that installs `{native-pkg-name}` and warns once at import. It does not install `{jvm-pkg-name}`. See xref:which-package.adoc#old-names[Old names].
3333

34-
The JVM package is self-contained. It carries a Java 25 runtime for its platform, so you do not install Java. Its only Python dependency is `JPype1` 1.5.0 or later (the Java-Python bridge), which `uv add` installs with it. The native package needs no Java and no JPype. Optional extras install the columnar helpers of the native package: `[numpy]`, `[arrow]`, `[pandas]` and `[polars]`.
34+
The JVM package is self-contained. It carries a Java 25 runtime for its platform, so you do not install Java. Its only Python dependency is `JPype1` 1.5.0 or later (the Java-Python bridge), which `uv add` installs with it. On Python 3.11 it stays below 1.8: there `JPype1` 1.8.0 ends the process with a segmentation fault when Python raises certain exceptions inside it, for example when Ctrl-C arrives during a query. The native package needs no Java and no JPype. Optional extras install the columnar helpers of the native package: `[numpy]`, `[arrow]`, `[pandas]` and `[polars]`.
35+
36+
// REMOVE WHEN: 26.12.1 is old enough that no supported release accepts JPype1 1.8 on Python 3.11
37+
NOTE: *Releases up to 26.11.1.post4 on Python 3.11.* These releases of `{jvm-pkg-name}`, the 26.12.1 pre-releases up to 26.12.1.dev2, and the releases under the former JVM package name (xref:which-package.adoc#old-names[Old names]) up to 26.10.2.post1 (also on Python 3.10) accept `JPype1` 1.8.0. Add the limit to your own project with `uv add "jpype1<1.8"`. Python 3.12 and later do not need it.
3538

3639
[[requirements]]
3740
== Requirements

‎pyproject.toml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,13 @@ classifiers = [
4141
"Topic :: Software Development :: Libraries :: Python Modules",
4242
]
4343

44+
# CAP on CPython 3.11: jpype1 1.8.0 ends the process with a segmentation fault there when an exception that CPython
45+
# holds without an instance goes through JPype, such as the KeyboardInterrupt of a Ctrl-C while a query calls a Python
46+
# function, or the StopIteration of next(). CPython 3.12 and later always hold an instance and are not affected.
47+
# REMOVE THE CAP when a newer jpype1 passes tests/test_jpype_bare_exceptions.py on Python 3.11.
4448
dependencies = [
45-
"jpype1>=1.5.0",
49+
"jpype1>=1.5.0,<1.8; python_version < '3.12'",
50+
"jpype1>=1.5.0; python_version >= '3.12'",
4651
]
4752

4853
[tool.uv]

‎tests/conftest.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
"test_jar_provenance.py": "jar fingerprint of the JVM wheel",
149149
"test_jar_closure.py": "jar closure of the JVM wheel",
150150
"test_java_package_shadowing.py": "JPype package import hooks",
151+
"test_jpype_bare_exceptions.py": "the installed JPype of the JVM wheel",
151152
"test_wheel_platform_tag.py": "JVM wheel tag",
152153
"test_wheel_tags.py": "JVM wheel tag (py3-none-<platform>)",
153154
"test_wheel_size.py": "JVM wheel size",
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
"""The installed JPype survives an exception that CPython holds without an instance.
2+
3+
jpype1 1.8.0 on CPython 3.11 ends the process with a segmentation fault when such an exception
4+
goes through JPype's own code: the ``KeyboardInterrupt`` of a Ctrl-C, or the ``StopIteration`` of
5+
``next()``. CPython 3.12 and later always hold an instance. ``pyproject.toml`` keeps jpype1 below
6+
1.8 on CPython 3.11, and this test fails when the installed JPype has the fault.
7+
8+
Each case runs in a child process, because the fault ends the process it happens in. Nothing
9+
depends on timing: ``signal.raise_signal`` and ``next()`` raise at a fixed point.
10+
"""
11+
12+
import subprocess # nosec B404 - test-controlled child process
13+
import sys
14+
15+
import pytest
16+
17+
_CHILD = r"""
18+
import signal
19+
import sys
20+
21+
import jpype
22+
23+
from arcadedb.jvm import start_jvm
24+
25+
start_jvm(heap_size="256m")
26+
# a parent that ignores SIGINT hands that to its child, and Python then installs no handler
27+
signal.signal(signal.SIGINT, signal.default_int_handler)
28+
29+
30+
def exhausted_iterator():
31+
next(iter([]))
32+
33+
34+
def ctrl_c():
35+
signal.raise_signal(signal.SIGINT)
36+
37+
38+
class Number:
39+
def __index__(self):
40+
signal.raise_signal(signal.SIGINT)
41+
return 1
42+
43+
__int__ = __index__
44+
45+
46+
case = sys.argv[1]
47+
print("jpype", jpype.__version__, flush=True)
48+
try:
49+
if case == "conversion":
50+
jpype.JInt(Number())
51+
else:
52+
function = {"stop_iteration": exhausted_iterator, "ctrl_c": ctrl_c}[case]
53+
supplier = jpype.JProxy("java.util.function.Supplier", dict={"get": function})
54+
jpype.JClass("java.util.Optional").empty().orElseGet(supplier)
55+
except BaseException as exc:
56+
print("raised", type(exc).__name__, flush=True)
57+
"""
58+
59+
60+
@pytest.mark.parametrize(
61+
"case, expected",
62+
[
63+
# a Java method calls a Python function
64+
("stop_iteration", "StopIteration"),
65+
("ctrl_c", "KeyboardInterrupt"),
66+
# no Java-to-Python call: JPype converts a Python object for Java
67+
("conversion", "KeyboardInterrupt"),
68+
],
69+
)
70+
def test_jpype_raises_instead_of_ending_the_process(case, expected):
71+
result = (
72+
subprocess.run( # nosec B603 - fixed argv, no shell, test-owned code string
73+
[sys.executable, "-c", _CHILD, case],
74+
capture_output=True,
75+
text=True,
76+
timeout=300,
77+
check=False,
78+
)
79+
)
80+
said = f"exit {result.returncode}\n{result.stdout}\n{result.stderr[-2000:]}"
81+
# the crash ends the child process, so its exit code is not 0
82+
assert result.returncode == 0, said
83+
assert result.stdout.split()[-2:] == ["raised", expected], said

0 commit comments

Comments
 (0)