Project

General

Profile

Actions

Bug #75768

open
BK NM

PyO3 workaround uses hardcoded python3 from PATH for interpreter execution

Bug #75768: PyO3 workaround uses hardcoded python3 from PATH for interpreter execution

Added by benaryorg Katze 8 months ago. Updated 17 days ago.

Status:
New
Priority:
Normal
Category:
ceph-mgr
Target version:
-
Due date:
% Done:

0%

Source:
Community (user)
Backport:
Regression:
Yes
Severity:
3 - minor
Reviewed:
Affected Versions:
ceph-qa-suite:
Pull request ID:
Tags (freeform):
Merge Commit:
Fixed In:
Released In:
Upkeep Timestamp:

Description

Bug #64213: MGR modules incompatible with later PyO3 versions - PyO3 modules may only be initialized once per interpreter process has introduced a new mechanic for executing any cryptography related functionality in a separate cleanly spawned Python interpreter.
This was and is necessary since PyO3 libraries, i.e. Python libraries mainly written in Rust, do not currently support Python subinterpreters, which ceph-mgr explicitly uses.

However the way the merged code does the spawning of that interpreter boils down to executing python3 from PATH to execute the relevant code which is part of the ceph-common Python library.
The problem here is that it is not guaranteed that this python3 is the one that ceph-common is installed for, or even that it is the correct version.
Many distributions allow multiple versions of Python to be installed at the same time, and if Ceph was installed for Python 3.12, but the default Python 3 was, say, 3.13, then this would most likely break.
That is unless you had Ceph installed for both versions at which point you could run into any number of other issues including version mismatches.
This fails, for instance, when packaging Ceph Tentacle in nixpkgs which does not have python3 on its PATH at all (or if it does it's because a user has put an interpreter there, which in turn most likely does not have ceph-common installed).

Now the way you would usually do this in the most pythonic way is to use the multiprocessing library or any other related mechanics and completely avoid having to know about any of those details.
If for some reason you could not use those, you would probably want to use at least sys.executable to determine which Python to use.
However given that Ceph uses libpython3 with its own executables (such as ceph-mgr) things get a little more complicated.
I do not want to assume why the implementation is what it is currently, however if I had to guess, I'd probably say that multiprocessing simply didn't work at all, and that sys.executable was broken too.
Which is true.
As of time of writing the Python environment in which ceph-mgr modules run does not know about its Python interpreter, which subsequently breaks sys.executable and the multiprocessing library.

So working backwards we can:

1. figure out why Ceph doesn't know about its Python interpreter, despite getting the interpreter explicitly passed via CMake.
2. correct for that behaviour
3. use the Python facilities (to any degree) to ensure the correct Python interpreter is used

NM Updated by Nitzan Mordechai 6 months ago Actions #1

  • Assignee set to Nitzan Mordechai

UB Updated by Utkarsh Bhatt 2 months ago Actions #2

In Ceph 20.2.4, WCHAR stringifies the macro name instead of expanding it. GDB on the binary (built from 20.2.4) confirms Python receives U"MGR_PYTHON_EXECUTABLE", leaving sys.executable empty. This also breaks Cephadm bootstrap under Python 3.14 (with pyo3 separate interpreter not resolving).

KC Updated by Kefu Chai 21 days ago Actions #3

Utkarsh Bhatt wrote in #note-2:

In Ceph 20.2.4, WCHAR stringifies the macro name instead of expanding it. GDB on the binary (built from 20.2.4) confirms Python receives U"MGR_PYTHON_EXECUTABLE", leaving sys.executable empty. This also breaks Cephadm bootstrap under Python 3.14 (with pyo3 separate interpreter not resolving).

https://github.com/ceph/ceph/pull/73050 addresses this problem.

BK Updated by benaryorg Katze 17 days ago Actions #4

I'll proceed to drop fd61d26 from 67904 as soon as 73050 hits then.

Actions

Also available in: PDF Atom