# How to begin to troubleshoot an XWiki crash?

**URL:** <https://forum.xwiki.org/t/how-to-begin-to-troubleshoot-an-xwiki-crash/16270>\
**Category:** Help / Discuss\
**Created:** [January 16, 2025, 12:33pm UTC](https://forum.xwiki.org/t/how-to-begin-to-troubleshoot-an-xwiki-crash/16270 "2025-01-16T12:33:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![franciscol](https://forum.xwiki.org/letter_avatar_proxy/v4/letter/f/b5ac83/32.png) [@franciscol](https://forum.xwiki.org/u/franciscol)\
**Post date:** [January 16, 2025, 12:33pm UTC](https://forum.xwiki.org/t/how-to-begin-to-troubleshoot-an-xwiki-crash/16270/1 "2025-01-16T12:33:22Z")

</div>

Hello.

I have an XWiki 16.7.1 under Apache Tomcat 9.0.95 on a Debian based VM on GCP. Running with Java openjdk 17.0.13 2024-10-15

Yesterday the XWiki instance crashed and **I would like to know how can I start troubleshooting the ‘cause’ of the crash. And/or if I need to enable something on the instance to be able to catch the cause of the crash next time.**

![image](https://forum.xwiki.org/uploads/default/original/2X/6/63aaf2d1b894a2353364d8be28c99e7c8a158a84.png)  
This is what we saw on the page, seemingly Apache Tomcat was unable to find the internal website of XWiki, correct?

Thank you very much for any help.

Here’s the Catalina last log from yesterday with a SEVERE indicator:

```log
15-Jan-2025 19:47:41.439 SEVERE [Catalina-utility-1] org.apache.catalina.core.ContainerBase.threadStart Exception processing background thread
        java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
                at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
                at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
                at org.apache.catalina.core.ContainerBase.threadStart(ContainerBase.java:1097)
                at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessorMonitor.run(ContainerBase.java:1141)
                at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
                at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
                at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
                at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
                at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
                at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
                at java.base/java.lang.Thread.run(Thread.java:840)
        Caused by: java.lang.OutOfMemoryError: Java heap space
                at java.base/java.util.TreeMap.addEntry(TreeMap.java:765)
                at java.base/java.util.TreeMap.put(TreeMap.java:828)
                at java.base/java.util.TreeMap.put(TreeMap.java:534)
                at java.base/java.util.TreeSet.add(TreeSet.java:255)
                at java.base/java.util.AbstractCollection.addAll(AbstractCollection.java:336)
                at java.base/java.util.TreeSet.addAll(TreeSet.java:309)
                at org.apache.catalina.webresources.Cache.backgroundProcess(Cache.java:212)
                at org.apache.catalina.webresources.StandardRoot.backgroundProcess(StandardRoot.java:608)
                at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:4817)
                at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1172)
                at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1176)
                at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1176)
                at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1154)
                ... 7 more
15-Jan-2025 19:50:11.639 SEVERE [Catalina-utility-3] org.apache.catalina.core.ContainerBase.threadStart Exception processing background thread
        java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
                at java.base/java.util.concurrent.FutureTask.report(FutureTask.java:122)
                at java.base/java.util.concurrent.FutureTask.get(FutureTask.java:191)
                at org.apache.catalina.core.ContainerBase.threadStart(ContainerBase.java:1097)
                at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessorMonitor.run(ContainerBase.java:1141)
                at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
                at java.base/java.util.concurrent.FutureTask.runAndReset(FutureTask.java:305)
                at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:305)
                at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
                at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
                at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:63)
                at java.base/java.lang.Thread.run(Thread.java:840)
        Caused by: java.lang.OutOfMemoryError: Java heap space
```

---

<div class="post-metadata">

**Author:** ![vmassol](https://forum.xwiki.org/user_avatar/forum.xwiki.org/vmassol/32/6_2.png) [@vmassol](https://forum.xwiki.org/u/vmassol)\
**Post date:** [January 16, 2025, 12:50pm UTC](https://forum.xwiki.org/t/how-to-begin-to-troubleshoot-an-xwiki-crash/16270/2 "2025-01-16T12:50:03Z")

</div>

For general debugging:

- [https://dev.xwiki.org/xwiki/bin/view/Community/Debugging](https://dev.xwiki.org/xwiki/bin/view/Community/Debugging)

In your case the cause is clear:

> [@franciscol](#):
>
> `Caused by: java.lang.OutOfMemoryError: Java heap space`

You need to increase the memory given to Tomcat. See [https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Performances/#HMemory](https://www.xwiki.org/xwiki/bin/view/Documentation/AdminGuide/Performances/#HMemory)

---

<div class="post-metadata">

**Author:** ![franciscol](https://forum.xwiki.org/letter_avatar_proxy/v4/letter/f/b5ac83/32.png) [@franciscol](https://forum.xwiki.org/u/franciscol)\
**Post date:** [January 16, 2025, 1:16pm UTC](https://forum.xwiki.org/t/how-to-begin-to-troubleshoot-an-xwiki-crash/16270/3 "2025-01-16T13:16:10Z")

</div>

Ok, thank you Vincent.

I am leaning to believe that I have a memory leak somewhere, at least from what I can gather on the ‘memory histogram’ of the instance, it increases overtime and it’s a relatively small instance (in terms of users ~10):

 ![image](https://forum.xwiki.org/uploads/default/original/2X/8/8d600a55e97505f18f2ac9a5ab0b6f70d9ff9e05.png)  
 ![image](https://forum.xwiki.org/uploads/default/original/2X/3/33942511b9619e6973a353207442d5140d10dd90.png)

I’m currently running the following settings on the setenv.sh file @ `/opt/tomcat/apache-tomcat-9.0.95/bin/setenv.sh` based on the recommended settings from the page you linked. Should I use more?

```config
export JAVA_OPTS="$JAVA_OPTS -Xms1024M -Xmx1600M \
-Dfile.encoding=UTF-8 \
-Djava.awt.headless=true \
-Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true \
-Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true \
--add-opens java.base/java.lang=ALL-UNNAMED \
--add-opens java.base/java.io=ALL-UNNAMED \
--add-opens java.base/java.util=ALL-UNNAMED \
--add-opens java.base/java.util.concurrent=ALL-UNNAMED"

```

How can I find, if it is a memory leak, it?

---

<div class="post-metadata">

**Author:** ![tmortagne](https://forum.xwiki.org/user_avatar/forum.xwiki.org/tmortagne/32/4930_2.png) [@tmortagne](https://forum.xwiki.org/u/tmortagne)\
**Post date:** [January 16, 2025, 1:21pm UTC](https://forum.xwiki.org/t/how-to-begin-to-troubleshoot-an-xwiki-crash/16270/4 "2025-01-16T13:21:08Z")

</div>

The easiest to identify what is (maybe wrongly) using all that memory is to [enable automated memory dump](https://dev.xwiki.org/xwiki/bin/view/Community/Debugging#HAnalyzeOutOfMemoryissues).

---

<div class="post-metadata">

**Author:** ![franciscol](https://forum.xwiki.org/letter_avatar_proxy/v4/letter/f/b5ac83/32.png) [@franciscol](https://forum.xwiki.org/u/franciscol)\
**Post date:** [January 16, 2025, 1:24pm UTC](https://forum.xwiki.org/t/how-to-begin-to-troubleshoot-an-xwiki-crash/16270/5 "2025-01-16T13:24:47Z")

</div>

Hi Thomas.

Excellent,

If I understand the instructions correctly, I should just add those two parameters to my “setenv.sh” file, restart tomcat and then wait for the next crash.

My setenv.sh would look like:

```c
export JAVA_OPTS="$JAVA_OPTS -Xms1024M -Xmx1600M \
-Dfile.encoding=UTF-8 \
-Djava.awt.headless=true \
-Dorg.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH=true \
-Dorg.apache.catalina.connector.CoyoteAdapter.ALLOW_BACKSLASH=true \
--add-opens java.base/java.lang=ALL-UNNAMED \
--add-opens java.base/java.io=ALL-UNNAMED \
--add-opens java.base/java.util=ALL-UNNAMED \
--add-opens java.base/java.util.concurrent=ALL-UNNAMED \
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/opt/tomcat/apache-tomcat-9.0.95/memdumps"

```

Am I on the right path?

Thank you.

---

<div class="post-metadata">

**Author:** ![tmortagne](https://forum.xwiki.org/user_avatar/forum.xwiki.org/tmortagne/32/4930_2.png) [@tmortagne](https://forum.xwiki.org/u/tmortagne)\
**Post date:** [January 16, 2025, 3:05pm UTC](https://forum.xwiki.org/t/how-to-begin-to-troubleshoot-an-xwiki-crash/16270/6 "2025-01-16T15:05:10Z")

</div>

> [@franciscol](#):
>
> Am I on the right path?

Yes, that’s the idea. Next time you hit a `OutOfMemoryError`, java should take a snapshot of the memory exactly at that moment so that you can take a look at it.

---

<div class="post-metadata">

**Author:** ![franciscol](https://forum.xwiki.org/letter_avatar_proxy/v4/letter/f/b5ac83/32.png) [@franciscol](https://forum.xwiki.org/u/franciscol)\
**Post date:** [January 16, 2025, 3:06pm UTC](https://forum.xwiki.org/t/how-to-begin-to-troubleshoot-an-xwiki-crash/16270/7 "2025-01-16T15:06:11Z")

</div>

Thank you!

I’ll follow up on this thread once it crashes again.

Bests,

---

<div class="post-metadata">

**Author:** ![franciscol](https://forum.xwiki.org/letter_avatar_proxy/v4/letter/f/b5ac83/32.png) [@franciscol](https://forum.xwiki.org/u/franciscol)\
**Post date:** [January 20, 2025, 12:57pm UTC](https://forum.xwiki.org/t/how-to-begin-to-troubleshoot-an-xwiki-crash/16270/8 "2025-01-20T12:57:15Z")

</div>

Hello.  
I’ve downloaded the hprof files that got generated on Jan 17 and also Jan 20.

I downloaded and opened them on EclipseMemoryAnalyzer and this is what I see:

 ![image](https://forum.xwiki.org/uploads/default/original/2X/b/b13cd47fe4cf896d6d6517b88546e55724210e51.png)

The file is enourmous (~3GB) so I can’t share it here.  
What else can I provide?

I’m no Java expert so this is way beyond my comfort zone but if I can be steered at least in the correct direction or is there any documentation written for this?

The StackTrace is giving attached here (it’s very long!):  
[StackTrace.txt](https://forum.xwiki.org/uploads/short-url/3zfLmu5mQKRKhaBA3FIO6F3i3Z0.txt) (526.6 KB)

And also here’s my object list (I’m just blindly taking information from the analyzer, I have no clue where to look at hah)

 ![image](https://forum.xwiki.org/uploads/default/original/2X/8/88021a107e93f59e181694a8ef68aa1f39fe9844.png)

---

<div class="post-metadata">

**Author:** ![tmortagne](https://forum.xwiki.org/user_avatar/forum.xwiki.org/tmortagne/32/4930_2.png) [@tmortagne](https://forum.xwiki.org/u/tmortagne)\
**Post date:** [January 20, 2025, 1:30pm UTC](https://forum.xwiki.org/t/how-to-begin-to-troubleshoot-an-xwiki-crash/16270/9 "2025-01-20T13:30:14Z")

</div>

> [@franciscol](#):
>
> ![image](https://forum.xwiki.org/uploads/default/original/2X/b/b13cd47fe4cf896d6d6517b88546e55724210e51.png)

This screenshot seems to suggest that one of the scheduler jobs is using a lot of memory.

> [@franciscol](#):
>
> ![image](https://forum.xwiki.org/uploads/default/original/2X/8/88021a107e93f59e181694a8ef68aa1f39fe9844.png)

This suggests that this memory is spent on loading (and more importantly, keeping) a bunch of documents.

> [@franciscol](#):
>
> [StackTrace.txt](https://forum.xwiki.org/uploads/short-url/3zfLmu5mQKRKhaBA3FIO6F3i3Z0.txt) (526.6 KB)

In that stack trace, I see a reference to a LoggingEventListener component which is called for each document save, which itself seems to cause a document save. Given the size of that stack trace, it seems like this event listener is stuck in a loop where it triggers itself by saving the same document over and over (and eventually fill the memory with XWikiDocument instances).

Feels like someone experimented with listeners starting from [https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Tutorials/WritingEventListenerTutorial/#HLogwhenadocumentismodified](https://www.xwiki.org/xwiki/bin/view/Documentation/DevGuide/Tutorials/WritingEventListenerTutorial/#HLogwhenadocumentismodified).

---

<div class="post-metadata">

**Author:** ![franciscol](https://forum.xwiki.org/letter_avatar_proxy/v4/letter/f/b5ac83/32.png) [@franciscol](https://forum.xwiki.org/u/franciscol)\
**Post date:** [January 20, 2025, 1:51pm UTC](https://forum.xwiki.org/t/how-to-begin-to-troubleshoot-an-xwiki-crash/16270/10 "2025-01-20T13:51:58Z")

</div>

Thank you Tom.

You’re right, I’m now realizing that a colleague started to add that exact same code that you linked on every-single top page on our instance. Effectively breaking the site whenever someone opens one of those pages.

 ![image](https://forum.xwiki.org/uploads/default/original/2X/3/3baf0ec6148aed1b54980bbcf60693cff22cabb2.png)
