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

No segfault when Python reactions fail #2428

Merged
merged 2 commits into from
Oct 17, 2024
Merged

Conversation

edwardalee
Copy link
Collaborator

Before this PR, if a Python reaction fails with an exception, the exception is properly reported, but the process then segfaults. Here is a simple test case:

target Python
main reactor {
  reaction(startup) {=
    raise Exception("Reaction fails.")
  =}
}

This PR eliminates the explicit call to Py_FinalizeEx() on failure, relying instead on the Python runtime's own shutdown hooks.

Before this PR, running the above program results in the following:

$ bin/Test
---- System clock resolution: 1000 nsec
---- Start execution on Wed Oct 16 16:43:07 2024 ---- plus 713035000 nanoseconds
Environment 0: ---- Intializing start tag
Environment 0: ---- Spawning 1 workers.
ERROR: FATAL: Calling reaction _test_main.reaction_function_0 failed.
Traceback (most recent call last):
  File "/Users/edwardlee/LinguaFranca/test/Python/src-gen/Test/Test.py", line 46, in reaction_function_0
    raise Exception("Reaction fails.")
Exception: Reaction fails.
bin/Test: line 2: 54348 Segmentation fault: 11  /Users/edwardlee/.pyenv/shims/python3.10 /Users/edwardlee/LinguaFranca/test/Python/src-gen/Test/Test.py "$@"
$

After the change, we get this:

$ bin/Test
---- System clock resolution: 1000 nsec
---- Start execution on Wed Oct 16 16:40:45 2024 ---- plus 431395000 nanoseconds
Environment 0: ---- Intializing start tag
Environment 0: ---- Spawning 1 workers.
ERROR: FATAL: Calling reaction _test_main.reaction_function_0 failed.
Traceback (most recent call last):
  File "/Users/edwardlee/LinguaFranca/test/Python/src-gen/Test/Test.py", line 46, in reaction_function_0
    raise Exception("Reaction fails.")
Exception: Reaction fails.
$ 

This PR also aligns reactor-c to main (again).

Copy link
Member

@lhstrh lhstrh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@edwardalee edwardalee enabled auto-merge October 17, 2024 00:47
@edwardalee edwardalee added this pull request to the merge queue Oct 17, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 17, 2024
@Depetrol
Copy link
Collaborator

Depetrol commented Oct 17, 2024

I've been noticing this in other PRs as well, but the lsp test seems to yield inconsistent results between workflow runs. See this run and this run(manual rerun) on the same commit. I think this is due to randomly inserted errors in ErrorInserter.java.

@edwardalee edwardalee added this pull request to the merge queue Oct 17, 2024
@lhstrh
Copy link
Member

lhstrh commented Oct 17, 2024

It's not inconsistent, it's partial and randomized.

Merged via the queue into master with commit ce42657 Oct 17, 2024
24 checks passed
@edwardalee edwardalee deleted the python-graceful-failure branch October 17, 2024 15:41
@lhstrh lhstrh changed the title Do not segfault when Python reactions fail. No segfault when Python reactions fail Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants