You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
stacktrace dumping shell logic is causing test flakes #9685
the stack trace dumping logic is actually causing excess evaluations of commands, which means logic that loops while expect a certain result never sees that result.
in this case, we loop trying to create a key. we expect to see "key created" come back, once the app is available and responsive.
Instead, during one of the failed POST attempts (because the app isn't up yet) the stack trace logic gets invoked, and the stack trace logic itself ends up evaluating the curl command and doing another POST. That stack trace logic gets the "key created" response, which is useless.
Then the main loop continues and tries the POST again, but now it gets "key updated" and fails the test.
the test logic starts in
end-to-end/core.sh:46 (POST to create key 1337)
then enters the retry loop at
hack/util.sh:283 and ends up in the stack trace logic as a result of the eval on line 284.
If you look at the gist output, you can see we enter the stack trace logic at line 11 due to an RC=7 from curl.
then line line 39-41 of the gist you can see the curl command gets evaluated (still within the stack trace handling logic) and gets the "key created" response back.
i assume the issue is faulty quoting on line 39 where the eval within the stack trace handling logic occurs.
@stevekuznetsov in the interest of deflaking things as rapidly as possible, my preference is to disable the stack dumping logic until this is sorted out.
@bparees I do not agree with your diagnosis of the issue -- the stacktrace logic does not evaluate the command itself, it does:
set +o nounset
local -r last_command_with_vars="$(eval"echo \"${last_command}\"")"set -o nounset
as can be seen (with accompanying explanation) here.
If the Bash logic here is breaking, it is definitely because the trap is getting triggered and returning a different return code than that which originally triggered it -- I'll look into that, it's definitely a bug.
I would not suggest your approach. Simply refactor your loop to do this:
# if the eval doesn't succeed...if!eval${cmd};then
...
fi# if it does...ifeval${cmd};then
...
fi
In addition to cleaning up that Bash, the fix for this (which I won't be able to implement until I'm back on Tuesday) is to apply the following diff here:
if [[ -z"${errexit_set}" ]];then# if errexit wasn't set in the shell when the ERR signal was issued, then we can ignore the signal# as this is not cause for failure
- return 0
+ return"${return_code}"fi
in which we are clearly within the error handler and the curl command is clearly evaluated because we see the result of "key created" which is the expected (and non-reentrant) return value from the curl command.
we came into the error handling because the original curl command got an RC=7 (could not connect) which is expected since we are looping to wait for the app to be up. Then within the error handling, the curl command gets invoked again, which it should not.
@bparees Oh, I see... the tricksy embedded subshell. Sorry, you are correct. I had not looked far enough into the gist.
On some further thought, my fix above might not be applicable since it would cause a recursive error condition, and since it wouldn't change the eval, anyway. I think it's most likely impossible to have an undetectable trap (i.e. one that returns with the same code as the command that triggered it) in this case, I think that's OK for two reasons, nevermind, Bash has magic that makes this possible, but in either case :
our use of set +e blocks is bad form and should be refactored ASAP
the eval && [[ $? = 0]] code is also not idiomatic and fragile, whereas if ! eval ${cmd}; then or while ! eval ${cmd}; doare idiomatic and more robust
However, I don't think there's a good argument for arguing that the stacktrace should ever actually evaluate any code, and against the use of a construct like [[ "$( some_cmd )" = "expected_output" ]]. Therefore, I think the eval to determine variables in the failing command feature should be removed or reconsidered. @smarterclayton you won't appreciate that but it's unfortunately necessary.
I think it's most likely impossible to have an undetectable trap (i.e. one that returns with the same code as the command that triggered it) in this case
To clarify this statement:
In the current scenario, we have the stacktrace as code that lives trapped on the ERR signal. ERR is a pseudo-signal that Bash generates. A trap on ERR is fired in the same set of cases where set -o errexit would trigger an EXIT pseudo-signal and exit behavior.
Since our code has blocks that do and blocks that do not use set -o errexit, we only honor the ERR trap if set -o errexit is on, as we only consider an error a failure in those environments.
Since any code executing in the trap ERR block will have a return code, it will overwrite the previous $?.
Since we have something sitting in trap ERR, we can't return in our error trap with any non-zero code. as it will re-trigger the trap infinitely until Bash segfaults by overflowing it's stack.
Therefore, there cannot exist an ERR trap that does not change the exit code. This isn't terrible since Bash seemingly has some magic by which the original error code is persisted through the trap (as we can see here [maybe @Miciah can explain what, exactly, happens]).
In the future, as we move away from blocks that use set +o errexit or set +e, we can actually move to never need set -o errexit as our trap ERR block will always be called when previously the errexit would have triggered an exit. In the current state, we're actually not getting errexit to send the EXIT signal anyway, I don't think, since a complete run of os::log::stacktrace will literally exit at the end and trigger the EXIT signal that way.
Activity
bparees commentedon Jul 2, 2016
you can see a full build showing this issue here:
https://ci.openshift.redhat.com/jenkins/job/test_pull_requests_origin_integration/2806/consoleFull
bparees commentedon Jul 2, 2016
@stevekuznetsov in the interest of deflaking things as rapidly as possible, my preference is to disable the stack dumping logic until this is sorted out.
stevekuznetsov commentedon Jul 2, 2016
@bparees I do not agree with your diagnosis of the issue -- the stacktrace logic does not evaluate the command itself, it does:
as can be seen (with accompanying explanation) here.
If the Bash logic here is breaking, it is definitely because the trap is getting triggered and returning a different return code than that which originally triggered it -- I'll look into that, it's definitely a bug.
I would not suggest your approach. Simply refactor your loop to do this:
In all of the relevant cases.
stevekuznetsov commentedon Jul 2, 2016
In addition to cleaning up that Bash, the fix for this (which I won't be able to implement until I'm back on Tuesday) is to apply the following diff here:
bparees commentedon Jul 2, 2016
@stevekuznetsov there's no question that the curl command is getting invoked from within the stack trace/error handler logic, look at:
https://gist.github.com/bparees/5cd82c622dbfc9e6725653102110bd64#file-gistfile1-txt-L39-L42
in which we are clearly within the error handler and the curl command is clearly evaluated because we see the result of "key created" which is the expected (and non-reentrant) return value from the curl command.
we came into the error handling because the original curl command got an RC=7 (could not connect) which is expected since we are looping to wait for the app to be up. Then within the error handling, the curl command gets invoked again, which it should not.
stevekuznetsov commentedon Jul 2, 2016
@bparees Oh, I see... the tricksy embedded subshell. Sorry, you are correct. I had not looked far enough into the gist.
On some further thought, my fix above might not be applicable since it would cause a recursive error condition, and since it wouldn't change the
eval, anyway.I think it's most likely impossible to have an undetectable trap (i.e. one that returns with the same code as the command that triggered it) in this case, I think that's OK for two reasons, nevermind, Bash has magic that makes this possible, but in either case :set +eblocks is bad form and should be refactored ASAPeval && [[ $? = 0]]code is also not idiomatic and fragile, whereasif ! eval ${cmd}; thenorwhile ! eval ${cmd}; doare idiomatic and more robustHowever, I don't think there's a good argument for arguing that the stacktrace should ever actually evaluate any code, and against the use of a construct like
[[ "$( some_cmd )" = "expected_output" ]]. Therefore, I think theevalto determine variables in the failing command feature should be removed or reconsidered. @smarterclayton you won't appreciate that but it's unfortunately necessary.smarterclayton commentedon Jul 2, 2016
stevekuznetsov commentedon Jul 2, 2016
To clarify this statement:
ERRsignal.ERRis a pseudo-signal that Bash generates. AtraponERRis fired in the same set of cases whereset -o errexitwould trigger anEXITpseudo-signal andexitbehavior.set -o errexit, we only honor theERRtrap ifset -o errexitis on, as we only consider an error a failure in those environments.trap ERRblock will have a return code, it will overwrite the previous$?.trap ERR, we can'treturnin our error trap with any non-zero code. as it will re-trigger the trap infinitely until Bash segfaults by overflowing it's stack.ERRtrap that does not change the exit code. This isn't terrible since Bash seemingly has some magic by which the original error code is persisted through the trap (as we can see here [maybe @Miciah can explain what, exactly, happens]).In the future, as we move away from blocks that use
set +o errexitorset +e, we can actually move to never needset -o errexitas ourtrap ERRblock will always be called when previously theerrexitwould have triggered anexit. In the current state, we're actually not gettingerrexitto send theEXITsignal anyway, I don't think, since a complete run ofos::log::stacktracewill literallyexitat the end and trigger theEXITsignal that way.bparees commentedon Jul 2, 2016
as part of fixing this, please re-enable the stack tracing behavior that's being disabled in: #9676