-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GL shutdown on catchable OutOfMemoryError (#15889)
* GL shutdown on catchable OutOfMemoryError * Changelog added * Changelog renamed, because of mixed-repo situation * New entry in UPGRADING.md
- Loading branch information
1 parent
f16102e
commit 07a1515
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
type = "fixed" # One of: a(dded), c(hanged), d(eprecated), r(emoved), f(ixed), s(ecurity) | ||
message = "Fix problem with STOPPED reactor on OutOfMemoryError. This error stops the whole GL instance now, instead of constantly logging errors related to stopped reactor." | ||
|
||
issues = ["graylog-plugin-enterprise#4980"] | ||
pulls = ["15889"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...java/org/graylog2/bootstrap/uncaughtexeptions/DefaultUncaughtExceptionHandlerCreator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (C) 2020 Graylog, Inc. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the Server Side Public License, version 1, | ||
* as published by MongoDB, Inc. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* Server Side Public License for more details. | ||
* | ||
* You should have received a copy of the Server Side Public License | ||
* along with this program. If not, see | ||
* <http://www.mongodb.com/licensing/server-side-public-license>. | ||
*/ | ||
package org.graylog2.bootstrap.uncaughtexeptions; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
public class DefaultUncaughtExceptionHandlerCreator { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(DefaultUncaughtExceptionHandlerCreator.class); | ||
|
||
public DefaultUncaughtExceptionHandlerCreator() { | ||
Thread.setDefaultUncaughtExceptionHandler((t, e) -> { | ||
if (!(e instanceof ThreadDeath)) { | ||
defaultHandling(t, e); | ||
if (e instanceof OutOfMemoryError) { | ||
outOfMemoryHandling(t); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
private void outOfMemoryHandling(final Thread t) { | ||
LOG.error("OutOfMemoryError encountered in thread " + t.getName() + ", Graylog instance will be shut down."); | ||
final Runtime runtime = Runtime.getRuntime(); | ||
LOG.info("Free JVM memory : " + runtime.freeMemory()); | ||
LOG.info("Total JVM memory : " + runtime.totalMemory()); | ||
LOG.info("Max JVM memory : " + runtime.maxMemory()); | ||
|
||
System.exit(1); | ||
} | ||
|
||
private void defaultHandling(final Thread t, final Throwable e) { | ||
//see ThreadGrooup.uncaughtException -> we don't want to remove the well-known "printStackTrace" uncaught exception handling | ||
System.err.print("Exception in thread \"" | ||
+ t.getName() + "\" "); | ||
e.printStackTrace(System.err); | ||
} | ||
} |