From 8fc2415b806d576c57095e6cd103fe246aa965ac Mon Sep 17 00:00:00 2001 From: Taewoon Kim Date: Sun, 29 Nov 2026 23:31:30 +0900 Subject: [PATCH] arcadedb-jvm on Python 3.11: keep jpype1 below 1.8, which crashes the process on Ctrl-C 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. --- README.md | 2 +- docs/modules/ROOT/pages/installation.adoc | 5 +- pyproject.toml | 7 +- tests/conftest.py | 1 + tests/test_jpype_bare_exceptions.py | 83 +++++++++++++++++++++++ 5 files changed, 95 insertions(+), 3 deletions(-) create mode 100644 tests/test_jpype_bare_exceptions.py diff --git a/README.md b/README.md index 895d217a..e9c5f03d 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ uv add arcadedb-jvm # JVM, for heavy long-running loads > 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`. -- 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)). +- 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)). - Linux x86_64 and ARM64, macOS on Apple Silicon, Windows x86_64, for both packages. The Windows wheel of `arcadedb` is the newest. - Import name: `arcadedb`. Check which package you have with `python -c "import arcadedb; print(arcadedb.__backend__)"`. It prints `native` or `jvm`. - Optional extras: `arrow`, `pandas`, `polars`, `vector` for `arcadedb-jvm`; `numpy`, `arrow`, `pandas`, `polars` for `arcadedb`. diff --git a/docs/modules/ROOT/pages/installation.adoc b/docs/modules/ROOT/pages/installation.adoc index 4ebf58bd..19dee837 100644 --- a/docs/modules/ROOT/pages/installation.adoc +++ b/docs/modules/ROOT/pages/installation.adoc @@ -31,7 +31,10 @@ NOTE: *First release.* The first release of this layout is 26.11.1, and both pac // REMOVE WHEN: the old arcadedb-embedded* shims are retired and two releases have shipped with the two-package layout allow-old-name 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]. -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]`. +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]`. + +// REMOVE WHEN: 26.12.1 is old enough that no supported release accepts JPype1 1.8 on Python 3.11 +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. [[requirements]] == Requirements diff --git a/pyproject.toml b/pyproject.toml index a80dd87a..9a29483f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,8 +41,13 @@ classifiers = [ "Topic :: Software Development :: Libraries :: Python Modules", ] +# CAP on CPython 3.11: jpype1 1.8.0 ends the process with a segmentation fault there when an exception that CPython +# holds without an instance goes through JPype, such as the KeyboardInterrupt of a Ctrl-C while a query calls a Python +# function, or the StopIteration of next(). CPython 3.12 and later always hold an instance and are not affected. +# REMOVE THE CAP when a newer jpype1 passes tests/test_jpype_bare_exceptions.py on Python 3.11. dependencies = [ - "jpype1>=1.5.0", + "jpype1>=1.5.0,<1.8; python_version < '3.12'", + "jpype1>=1.5.0; python_version >= '3.12'", ] [tool.uv] diff --git a/tests/conftest.py b/tests/conftest.py index b545a80e..1a5f35d3 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -148,6 +148,7 @@ "test_jar_provenance.py": "jar fingerprint of the JVM wheel", "test_jar_closure.py": "jar closure of the JVM wheel", "test_java_package_shadowing.py": "JPype package import hooks", + "test_jpype_bare_exceptions.py": "the installed JPype of the JVM wheel", "test_wheel_platform_tag.py": "JVM wheel tag", "test_wheel_tags.py": "JVM wheel tag (py3-none-)", "test_wheel_size.py": "JVM wheel size", diff --git a/tests/test_jpype_bare_exceptions.py b/tests/test_jpype_bare_exceptions.py new file mode 100644 index 00000000..79249650 --- /dev/null +++ b/tests/test_jpype_bare_exceptions.py @@ -0,0 +1,83 @@ +"""The installed JPype survives an exception that CPython holds without an instance. + +jpype1 1.8.0 on CPython 3.11 ends the process with a segmentation fault when such an exception +goes through JPype's own code: the ``KeyboardInterrupt`` of a Ctrl-C, or the ``StopIteration`` of +``next()``. CPython 3.12 and later always hold an instance. ``pyproject.toml`` keeps jpype1 below +1.8 on CPython 3.11, and this test fails when the installed JPype has the fault. + +Each case runs in a child process, because the fault ends the process it happens in. Nothing +depends on timing: ``signal.raise_signal`` and ``next()`` raise at a fixed point. +""" + +import subprocess # nosec B404 - test-controlled child process +import sys + +import pytest + +_CHILD = r""" +import signal +import sys + +import jpype + +from arcadedb.jvm import start_jvm + +start_jvm(heap_size="256m") +# a parent that ignores SIGINT hands that to its child, and Python then installs no handler +signal.signal(signal.SIGINT, signal.default_int_handler) + + +def exhausted_iterator(): + next(iter([])) + + +def ctrl_c(): + signal.raise_signal(signal.SIGINT) + + +class Number: + def __index__(self): + signal.raise_signal(signal.SIGINT) + return 1 + + __int__ = __index__ + + +case = sys.argv[1] +print("jpype", jpype.__version__, flush=True) +try: + if case == "conversion": + jpype.JInt(Number()) + else: + function = {"stop_iteration": exhausted_iterator, "ctrl_c": ctrl_c}[case] + supplier = jpype.JProxy("java.util.function.Supplier", dict={"get": function}) + jpype.JClass("java.util.Optional").empty().orElseGet(supplier) +except BaseException as exc: + print("raised", type(exc).__name__, flush=True) +""" + + +@pytest.mark.parametrize( + "case, expected", + [ + # a Java method calls a Python function + ("stop_iteration", "StopIteration"), + ("ctrl_c", "KeyboardInterrupt"), + # no Java-to-Python call: JPype converts a Python object for Java + ("conversion", "KeyboardInterrupt"), + ], +) +def test_jpype_raises_instead_of_ending_the_process(case, expected): + result = ( + subprocess.run( # nosec B603 - fixed argv, no shell, test-owned code string + [sys.executable, "-c", _CHILD, case], + capture_output=True, + text=True, + timeout=300, + check=False, + ) + ) + said = f"exit {result.returncode}\n{result.stdout}\n{result.stderr[-2000:]}" + # the crash ends the child process, so its exit code is not 0 + assert result.returncode == 0, said + assert result.stdout.split()[-2:] == ["raised", expected], said