From 2c2264d8d0be6a04312413aae324d9589775e9ba Mon Sep 17 00:00:00 2001 From: Britta Weber Date: Wed, 13 Jan 2016 13:40:44 +0100 Subject: [PATCH 1/2] Avoid circular reference in exception 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 #15941 closes #15941 --- .../main/java/org/elasticsearch/index/translog/Translog.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/main/java/org/elasticsearch/index/translog/Translog.java b/core/src/main/java/org/elasticsearch/index/translog/Translog.java index 88e4b06421e..fdf39a86515 100644 --- a/core/src/main/java/org/elasticsearch/index/translog/Translog.java +++ b/core/src/main/java/org/elasticsearch/index/translog/Translog.java @@ -576,8 +576,12 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC 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()); } } } From 0c08d796c5bf32991b32cead4b594b4e6198d183 Mon Sep 17 00:00:00 2001 From: Britta Weber Date: Wed, 13 Jan 2016 16:27:26 +0100 Subject: [PATCH 2/2] assert before we set the suppressed --- .../main/java/org/elasticsearch/index/translog/Translog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/index/translog/Translog.java b/core/src/main/java/org/elasticsearch/index/translog/Translog.java index fdf39a86515..0001fda0752 100644 --- a/core/src/main/java/org/elasticsearch/index/translog/Translog.java +++ b/core/src/main/java/org/elasticsearch/index/translog/Translog.java @@ -580,8 +580,8 @@ public class Translog extends AbstractIndexShardComponent implements IndexShardC // 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()); + ex.addSuppressed(inner); } } }