Marton Szasz created MINIFICPP-2766:
---------------------------------------
Summary: C++ exceptions can't be handled in Python processors
Key: MINIFICPP-2766
URL: https://issues.apache.org/jira/browse/MINIFICPP-2766
Project: Apache NiFi MiNiFi C++
Issue Type: Bug
Reporter: Marton Szasz
from JS Marier on Slack:
{noformat}
Hello MiNiFi. I believe there is an issue with exception handling and the
Python interpreter.
If a C++ function called by a Python function raises a C++ exception, this C++
exception is not translated to a Python exception. The result is that the C++
exception unwinds over the C stack frames all the way back to the catch in
ProcessSessionImpl::rollback. This is inconvenient because this rollback
restores the flowfiles to their previous state, effectively making MiNiFi retry
that forever. Unwinding over the Python interpreter's stack frames could cause
issues in general, but that would be due to implementation details of that
interpreter.
I can't remember precisely in what context I encountered that issue. However, I
think it would be best to translate the C++ exception to a Python exception so
that the caller (typically a Python processor) can catch it and deal with it
appropriately, possibly by transferring the offending flowfile to the failure
relation.
The sketch of a solution involves adding something like this:
#define PYTHON_METHOD_BEGIN \
try {
#define PYTHON_METHOD_END \
} catch (const std::exception& e) { \
PyErr_SetString(PyExc_Exception, e.what()); \
return nullptr; \
}Those two macros would then be added at the beginning and end of each method
callable from the Python interpreter, e.g. PyInputStream::read(PyInputStream*
self, PyObject* args).
If that sounds like a legitimate problem and a reasonable solution, I'll be
happy to provide a patch that implements this.
{noformat}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)