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

jl_current_exception doesn't return the exception when called from atexit #47472

Closed
simonbyrne opened this issue Nov 6, 2022 · 6 comments
Closed
Labels
regression Regression in behavior compared to a previous version

Comments

@simonbyrne
Copy link
Contributor

In Julia 1.8 (and earlier):

├ julia -e 'atexit(() -> @show ccall(:jl_current_exception, Any, ())); error("oh no")'
ERROR: oh no
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] top-level scope
   @ none:1
ccall(:jl_current_exception, Any, ()) = ErrorException("oh no")

On the current nightly:

├ ./julia --startup-file=no -e 'atexit(() -> @show ccall(:jl_current_exception, Any, ())); error("oh no")'
ERROR: oh no
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] top-level scope
   @ none:1
ccall(:jl_current_exception, Any, ()) = nothing

There is similar behavior with current_exceptions() as well. This is a problem as there isn't a good way to determine if we're exiting due to an error or not (#35981)

@gbaraldi
Copy link
Member

gbaraldi commented Nov 7, 2022

Bisected to e34860e

@simonbyrne
Copy link
Contributor Author

@vtjnash any suggestions for what we can do here? We don't need to recreate the old behavior, just need some way to find the error stack when we exit due to an error.

@simonbyrne simonbyrne added the regression Regression in behavior compared to a previous version label Nov 7, 2022
@JeffBezanson
Copy link
Member

How do MPI bindings for other languages handle this?

@simonbyrne
Copy link
Contributor Author

simonbyrne commented Nov 8, 2022

The official C and Fortran ones require you to manually call MPI_Finalize, or call MPI_Abort on an error.

mpi4py, which is probably the most widely used 3rd party one, and the closest to MPI.jl, by default adds an atexit hook that calls MPI_Finalize:
https://github.com/mpi4py/mpi4py/blob/bd9e2a58be3689983f9fff798447a76796b10e5a/src/mpi4py/MPI/atimport.pxi#L328-L334
It also provides a wrapper module
https://mpi4py.readthedocs.io/en/stable/mpi4py.run.html
that will check catch any errors and trigger an MPI_Abort if necessary
https://github.com/mpi4py/mpi4py/blob/b7ca61d43aec14d23d64490d2b8591974cb81d4e/src/mpi4py/run.py#L188

@JeffBezanson
Copy link
Member

Ok, so mpi4py is only able to use MPI_Abort if you go through that wrapper, but we want it to work without such a wrapper?

@simonbyrne
Copy link
Contributor Author

Ideally, yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

4 participants