Skip to contentSkip to conversation

Why FailedAssertion is not my favorite exception

DISCUSSION Adam C. Emerson 3 participants 5 messages Dec 4, 2015

lore
Share & tools
lore
#0 lore raw

Noble Creators of the Squid Cybernetic Swimming in a Distributed Data Sea,

There is a spectre haunting src/common/assert.cc: The spectre of throw FailedAssertion.

This seemingly inconsequential yet villainous statement destroys the stack frame in which a failing assert statement is evaluated-- a stack frame of great interest to those hoping to divine the cause of such failures-- at the moment of their detection.

This consequence follows from the hope that some caller might be able to catch and recover from the failure. That is an unworthy goal, for any failure sufficiently dire to rate an 'assert' is a failure from which there can be no recovery. As I survey the code, I see FailedAssertion is only caught as part of unit tests and in a few small programs where it lead to an immediate exit.

Therefore! If there is no objection, I would like to submit a patch that will replace 'throw FailedException' with abort(). In support of this goal, the patch will also remove attempts to catch FailedException from driver programs like librados-config and change tests expecting a throw of FailedAssertion to use the EXPECT_DEATH or ASSERT_DEATH macros instead.

These changes, taken together, should be non-disruptive and make debugging easier.

Thank you all.

Signature · 3 lines
Senior Software Engineer           Red Hat Storage, Ann Arbor, MI, US
IRC: Aemerson@{RedHat, OFTC, Freenode}
0x80F7544B90EDBFB9 E707 86BA 0C1B 62CC 152C  7C12 80F7 544B 90ED BFB9
#1 lore raw
Quoted 17 lines · Adam C. Emerson

Noble Creators of the Squid Cybernetic Swimming in a Distributed Data Sea,

There is a spectre haunting src/common/assert.cc: The spectre of throw FailedAssertion.

This seemingly inconsequential yet villainous statement destroys the stack frame in which a failing assert statement is evaluated-- a stack frame of great interest to those hoping to divine the cause of such failures-- at the moment of their detection.

This consequence follows from the hope that some caller might be able to catch and recover from the failure. That is an unworthy goal, for any failure sufficiently dire to rate an 'assert' is a failure from which there can be no recovery. As I survey the code, I see FailedAssertion is only caught as part of unit tests and in a few small programs where it lead to an immediate exit.

Quoted 8 lines

Therefore! If there is no objection, I would like to submit a patch that will replace 'throw FailedException' with abort(). In support of this goal, the patch will also remove attempts to catch FailedException from driver programs like librados-config and change tests expecting a throw of FailedAssertion to use the EXPECT_DEATH or ASSERT_DEATH macros instead.

These changes, taken together, should be non-disruptive and make debugging easier.

Sounds good. Feel free to replace the code the deliberately induces a segv with abort(), too... I wasn't aware of it when writing the original code.

sage

#2 lore raw
In reply to Adam C. Emerson
Quoted 17 lines · Adam C. Emerson

Noble Creators of the Squid Cybernetic Swimming in a Distributed Data Sea,

There is a spectre haunting src/common/assert.cc: The spectre of throw FailedAssertion.

This seemingly inconsequential yet villainous statement destroys the stack frame in which a failing assert statement is evaluated-- a stack frame of great interest to those hoping to divine the cause of such failures-- at the moment of their detection.

This consequence follows from the hope that some caller might be able to catch and recover from the failure. That is an unworthy goal, for any failure sufficiently dire to rate an 'assert' is a failure from which there can be no recovery. As I survey the code, I see FailedAssertion is only caught as part of unit tests and in a few small programs where it lead to an immediate exit.

Quoted 8 lines

Therefore! If there is no objection, I would like to submit a patch that will replace 'throw FailedException' with abort(). In support of this goal, the patch will also remove attempts to catch FailedException from driver programs like librados-config and change tests expecting a throw of FailedAssertion to use the EXPECT_DEATH or ASSERT_DEATH macros instead.

These changes, taken together, should be non-disruptive and make debugging easier.

I must be missing something here. As far as I can tell, "throw FailedAssertion" only happens in assert.cc, and I know that stuff doesn't destroy the relevant stack frames since I've pulled the info out of core dumps when debugging?
-Greg

#3 lore raw
Quoted 5 lines · Gregory Farnum

I must be missing something here. As far as I can tell, "throw FailedAssertion" only happens in assert.cc, and I know that stuff doesn't destroy the relevant stack frames since I've pulled the info out of core dumps when debugging?
-Greg

The behavior I'm seeing is that when I am attached to a process with gdb, and an assertion fails it bounces all the way up to terminate with an uncaught exception.

Signature · 3 lines
Senior Software Engineer           Red Hat Storage, Ann Arbor, MI, US
IRC: Aemerson@{RedHat, OFTC, Freenode}
0x80F7544B90EDBFB9 E707 86BA 0C1B 62CC 152C  7C12 80F7 544B 90ED BFB9
#4 lore raw
Quoted 10 lines · Adam C. Emerson
Quoted 5 lines · Gregory Farnum

I must be missing something here. As far as I can tell, "throw FailedAssertion" only happens in assert.cc, and I know that stuff doesn't destroy the relevant stack frames since I've pulled the info out of core dumps when debugging?
-Greg

The behavior I'm seeing is that when I am attached to a process with gdb, and an assertion fails it bounces all the way up to terminate with an uncaught exception.

Oh, yeah, I've no idea what it does when you're attached. I just want to make sure it's generating core dump files on assert failure (that is by far the most common way of generating and analyzing issues), which it looks like abort() does, so fine with me. :) -Greg