Skip to content

Commit

Permalink
Avoid circular reference in exception
Browse files Browse the repository at this point in the history
Don't set the suppressed Exception in Translog.closeOnTragicEvent(Exception ex) if it is an
AlreadyClosedException. ACE is thrown by the TranslogWriter and as cause might
contain the Exception that we add the suppressed ACE to. We then end up with a
circular reference where Exception A has a suppressed Exception B that has as cause A.
This would cause a stackoverflow when we try to serialize it.
For a more detailed description see elastic#15941

closes elastic#15941
  • Loading branch information
brwe committed Jan 13, 2016
1 parent 13c0b19 commit 2c2264d
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,12 @@ private void closeOnTragicEvent(Throwable ex) {
if (current.getTragicException() != null) {
try {
close();
} catch (AlreadyClosedException inner) {
// don't do anything in this case. The AlreadyClosedException comes from TranslogWriter and we should not add it as suppressed because
// will contain the Exception ex as cause. See also https://github.com/elastic/elasticsearch/issues/15941
} catch (Exception inner) {
ex.addSuppressed(inner);
assert (ex != inner.getCause());
}
}
}
Expand Down

0 comments on commit 2c2264d

Please sign in to comment.