Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix python persist crash if there is no global python block #4572

Conversation

bazsi
Copy link
Collaborator

@bazsi bazsi commented Jul 29, 2023

This is a refactor + a bugfix for a crash in our Python bindings, which happen in the configuration is using a Persist or a LogTemplate and there's no global python code block in the configuration anywhere.

The crash happens because if there's no global code block, our main module is never initialized. And this main module is what encapsulates the Python -> GlobalConfig association.

I found that there was no easy way to add the initialization of our main module, it was only driven from the grammar. Instead of adding yet another initialization to all our Python based components, I introduced PythonBinding a class shared by all our components and where I could add the relevant initialization.

I also split the python-main.c module into 3 files (python-startup, python-global and python-main) to make the size easier to manage.

This is WIP at the moment, as it's pretty late already and I am yet to do some testing myself. There's no NEWS file either.

This should fix the issue encountered by @ryanfaircloth

To trigger the crash, use a Python based source, with a Persist() instance so that you store the Python code in an external module and you DON'T have any global python code blocks.

The crash should happen as soon as the Persist() object is initialized.

@kira-syslogng
Copy link
Contributor

Build FAILURE

@MrAnno MrAnno force-pushed the fix-python-persist-crash-if-there-is-no-global-python-block branch 3 times, most recently from 7450d87 to 25bb1a3 Compare August 9, 2023 08:13
@kira-syslogng
Copy link
Contributor

Build FAILURE

bazsi and others added 12 commits August 9, 2023 11:57
The PythonBinding class encapsulates the basic parameters for interacting
with the Python object that contains the parsing logic. It will also
allow centralizing python related functionality across all of our
python components (e.g. destination, source, etc)

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
python-main contains multiple logical layers, let's split them.

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
…block

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: László Várady <laszlo.varady@anno.io>
@MrAnno MrAnno force-pushed the fix-python-persist-crash-if-there-is-no-global-python-block branch from 25bb1a3 to 4b1ac53 Compare August 9, 2023 09:57
@MrAnno MrAnno changed the title WIP: Fix python persist crash if there is no global python block Fix python persist crash if there is no global python block Aug 9, 2023
MrAnno
MrAnno previously approved these changes Aug 9, 2023
Signed-off-by: László Várady <laszlo.varady@anno.io>
@MrAnno MrAnno merged commit 9a08e35 into syslog-ng:master Aug 9, 2023
15 of 16 checks passed
@bazsi
Copy link
Collaborator Author

bazsi commented Aug 10, 2023

Thanks @MrAnno for finishing this up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants