Add correct exception logging in the ExecutorUtil#2384
Add correct exception logging in the ExecutorUtil#2384HoustonPutman merged 1 commit intoapache:mainfrom
Conversation
|
An example of how this would fix exception logging: Existing implementation: Fix: Notice how the cause-submitter-stacktrace ordering is now correct, and that the downstream error is actually being reported as the ultimate cause. This will also work even if the error/exception has its own causes. |
|
This took me a bit of experimenting with locally, but I understand what's going on now and agree that the new ordering is correct. Thanks for cleaning this up @HoustonPutman! |
| if (t instanceof OutOfMemoryError) { | ||
| throw t; | ||
| } | ||
| if (enableSubmitterStackTrace) { |
There was a problem hiding this comment.
Don't we still need to have this flag?
There was a problem hiding this comment.
I don't believe so. So the baseCause, which is now always logged, will be t (the real throwable) if submitterStackTrace is null. Since when enableSumbitterStackTrace==false then submitterStackTrace=null (logic from above), then we will only be logging t if enableSubmitterStackTrace==false. The submitterStackTraces will only be included if enableSubmitterStackTrace==true.
It is still a little different than the previous logic, which only logged the error message, but I think the spirit of the flag is still the same.
(cherry picked from commit 07606c7)
This actually logs the correct stack trace for an exception caught in the ExecutorUtil.
It also provides the correct ordering of "causes" unlike the way it was previously implemented, where the "cause" was actually the thread that called the Executor. Now the "cause" is the error in the executor, and the base exception is the thread that called the ExecutorUtil.
It may look strange that we always use an
Exceptionclass, but this is ok since these exceptions that we are copying are only made a few lines up and are always of classException. (They aren't real exceptions, they are merely storing the stackTrace of how the original thread called the Executor, or the tree of executor calls). Therefore, no information is being lost here.