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 #21369, exception state overwritten by caught internal errors #21434

Merged
merged 1 commit into from Apr 20, 2017

Conversation

JeffBezanson
Copy link
Sponsor Member

No description provided.

@ararslan ararslan added kind:bugfix This change fixes an existing bug domain:error handling Handling of exceptions by Julia or the user labels Apr 18, 2017
@ararslan ararslan requested a review from yuyichao April 18, 2017 19:25
src/gc.c Outdated
@@ -108,7 +108,7 @@ static void run_finalizer(jl_ptls_t ptls, jl_value_t *o, jl_value_t *ff)
JL_TRY {
size_t last_age = jl_get_ptls_states()->world_age;
jl_get_ptls_states()->world_age = jl_world_counter;
jl_apply(args, 2);
jl_apply_with_saved_exception_state(args, 2, 0);
jl_get_ptls_states()->world_age = last_age;
}
JL_CATCH {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should either remove this or keep it working. (Printing a warning if an unexpected error happens in a finalizer is probably still somewhat useful.)

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually didn't realized that this is what the 0 is for...

Copy link
Contributor

Choose a reason for hiding this comment

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

Though in that case, does the copying of backtrace actually do anything at all? If an error is thrown it'll just hit this catch and the exception and backtraces will still be overwritten? Seems that the saving should move to the caller of this function, outside the loop.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

Yes, it still does something, in case a finalizer catches and hides an exception. However you're right that saving the state inside this loop is inefficient. C is just not good for this kind of programming :(

Copy link
Contributor

Choose a reason for hiding this comment

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

in case a finalizer catches and hides an exception.

Ah, yeah.

C is just not good for this kind of programming :(

Agreed. Luckily, there's only one caller so it should be sufficient to add the saving logic to jl_gc_run_finalizers_in_lilst after releasing the finalizer lock.

@JeffBezanson
Copy link
Sponsor Member Author

Updated.

@JeffBezanson
Copy link
Sponsor Member Author

@vtjnash There's an interesting error on 64-bit linux on travis here where my change to static_eval apparently tries to call something in world 0. Why would this happen only on 64-bit travis/linux? Works locally.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Apr 19, 2017

I'm not sure why only x86-64 exercises this code path, but it is correct in observing that previously this function did not exercise any dynamic dispatch code, and with the change, it now is attempting to do so.

@JeffBezanson
Copy link
Sponsor Member Author

How could the current world get set to 0? Is there any code that does that?

@vtjnash
Copy link
Sponsor Member

vtjnash commented Apr 19, 2017

It's the default world. It can sometimes get triggered when you try to run _apply from invalid contexts, like inside codegen. In this case, world=1 would be sufficient however, so it's not too wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:error handling Handling of exceptions by Julia or the user kind:bugfix This change fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants