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

LOG(fatal) is supposed to throw an exception but it never throws because of abort from fclose(stderr) #1463

Open
YanzhaoW opened this issue Nov 16, 2023 · 3 comments

Comments

@YanzhaoW
Copy link

Describe the bug

std::cerr << "For later analysis we write a stack trace to " << corefile << std::endl;
if (freopen(corefile, "w", stderr)) {
gSystem->StackTrace();
fclose(stderr);
}
}
throw fair::FatalException("Fatal error occured. Exiting...");
}

Here the program somehow call the abort when calling fclose(stderr) in the if statement. Therefore, it never reaches to the throwing line.

To Reproduce
Add a printout just above the throw statement and the printout message never gets printed.

Expected behavior
Let it throw

@rbx
Copy link
Member

rbx commented Dec 18, 2023

A different idea:
a LOG call should never throw (unless it can't actually log) because of a severity level. It's job is just to make a log entry.
The way it is now is just historical, but it is not good - it is not loggers job to terminate your program. Deprecate/remove it.

If you really want to have a fatal call which throws, call it Fatal() or FATAL macro, which would internally first call LOG, and then throw.

@YanzhaoW
Copy link
Author

YanzhaoW commented Feb 7, 2024

Yeah, I agree. But would this be a huge breaking change? Many programs would not be terminated in the emergency, which could cause lots of segmentation fault.

@rbx
Copy link
Member

rbx commented Feb 19, 2024

I did a quick test with LOG(fatal) at (https://github.com/FairRootGroup/FairRoot/blob/dev/examples/MQ/serialization/data_generator/dataGenerator.cxx#L94) and it throws the exception as expected (which would itself lead to SIGABRT if uncaught).

Could you post a stacktrace to see a bit more detail? Also, what is the corefile filename and does it contain anything meaningful? Perhaps the failure happens there already.

I wonder why the close(stderr) is needed at all. Perhaps it is aborting because it is closed already at that point?

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

No branches or pull requests

2 participants