FairRoot icon indicating copy to clipboard operation
FairRoot copied to clipboard

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

Open YanzhaoW opened this issue 1 year ago • 3 comments

Describe the bug https://github.com/FairRootGroup/FairRoot/blob/fa7108b45684c729c2e88b12d7fbf4bbb5a4dc65/fairtools/FairLogger.cxx#L192-L203

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

YanzhaoW avatar Nov 16 '23 02:11 YanzhaoW

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.

rbx avatar Dec 18 '23 13:12 rbx

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.

YanzhaoW avatar Feb 07 '24 10:02 YanzhaoW

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?

rbx avatar Feb 19 '24 11:02 rbx