-
Notifications
You must be signed in to change notification settings - Fork 390
Fix: OOM didn't force Teku to quit #11241
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zilm13
wants to merge
10
commits into
Consensys-Incorporated:master
Choose a base branch
from
zilm13:oom-catchall
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3f74144
Fix: OOM didn't force Teku to quit
zilm13 64308bf
more
zilm13 9891bba
fix dependency check
zilm13 417a037
more checks covering deadlock #7166
zilm13 622a03e
small test refactor
zilm13 802ee70
Merge branch 'master' into oom-catchall
zilm13 d54affc
Ensure we will not break shutdown action on any intermediate error
zilm13 fb3a818
fix call to super could get around shutdown catch
zilm13 46e3ddf
ensure oom is caught with finally
zilm13 3946f6e
Merge branch 'master' into oom-catchall
rolfyone File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
136 changes: 136 additions & 0 deletions
136
.../async/src/test/java/tech/pegasys/teku/infrastructure/async/SafeFutureFatalErrorTest.java
This file contains hidden or 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,136 @@ | ||
| /* | ||
| * Copyright Consensys Software Inc., 2026 | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
| * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations under the License. | ||
| */ | ||
|
|
||
| package tech.pegasys.teku.infrastructure.async; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.concurrent.atomic.AtomicInteger; | ||
| import org.apache.logging.log4j.LogManager; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import tech.pegasys.teku.infrastructure.exceptions.ExitConstants; | ||
| import tech.pegasys.teku.infrastructure.exceptions.FatalErrorHandler; | ||
|
|
||
| /** | ||
| * Async code across Teku catches {@link Throwable} and turns it into a failed future or a log line. | ||
| * These tests confirm a fatal error taking those paths still shuts the node down. | ||
| */ | ||
| @SuppressWarnings("FutureReturnValueIgnored") | ||
| class SafeFutureFatalErrorTest { | ||
|
|
||
| private final AtomicInteger terminations = new AtomicInteger(0); | ||
| private final List<Integer> exitCodes = new ArrayList<>(); | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| FatalErrorHandler.overrideProcessTerminator( | ||
| (exitCode, gracefulTimeout) -> { | ||
| terminations.incrementAndGet(); | ||
| exitCodes.add(exitCode); | ||
| }); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void tearDown() { | ||
| FatalErrorHandler.restoreDefaultProcessTerminator(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldShutdownWhenFutureIsCompletedWithOutOfMemoryError() { | ||
| new SafeFuture<>().completeExceptionally(new OutOfMemoryError()); | ||
|
|
||
| assertThat(terminations).hasValue(1); | ||
| // Restarting is expected to recover from running out of memory | ||
| assertThat(exitCodes).containsExactly(ExitConstants.ERROR_EXIT_CODE); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldShutdownWhenActionThrowsOutOfMemoryError() { | ||
| SafeFuture.fromRunnable( | ||
| () -> { | ||
| throw new OutOfMemoryError(); | ||
| }); | ||
|
|
||
| assertThat(terminations).hasValue(1); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldShutdownWhenOutOfMemoryErrorIsPassedToAnExceptionHandler() { | ||
| failedWith(new OutOfMemoryError()).handleException(error -> {}); | ||
|
|
||
| assertThat(terminations).hasValue(1); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldShutdownWhenOutOfMemoryErrorIsOnlyLogged() { | ||
| failedWith(new OutOfMemoryError()).finishError(LogManager.getLogger()); | ||
|
|
||
| assertThat(terminations).hasValue(1); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldShutdownWhenOutOfMemoryErrorIsReplacedWithAFallbackValue() { | ||
| failedWith(new OutOfMemoryError()).exceptionally(error -> null); | ||
|
|
||
| assertThat(terminations).hasValue(1); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldShutdownWhenOutOfMemoryErrorIsPassedToAFinishErrorHandler() { | ||
| failedWith(new OutOfMemoryError()).finish(error -> {}); | ||
|
|
||
| assertThat(terminations).hasValue(1); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldShutdownWhenOutOfMemoryErrorIsObservedByWhenComplete() { | ||
| failedWith(new OutOfMemoryError()).whenComplete((result, error) -> {}); | ||
|
|
||
| assertThat(terminations).hasValue(1); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldShutdownWhenOutOfMemoryErrorIsNotOneOfTheIgnoredExceptions() { | ||
| failedWith(new OutOfMemoryError()).ignoreExceptions(IOException.class); | ||
|
|
||
| assertThat(terminations).hasValue(1); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldNotShutdownForOrdinaryFailures() { | ||
| failedWith(new IOException("nope")).handleException(error -> {}); | ||
| failedWith(new IOException("nope")).finishError(LogManager.getLogger()); | ||
| failedWith(new IOException("nope")).exceptionally(error -> null); | ||
| failedWith(new IOException("nope")).finish(error -> {}); | ||
| failedWith(new IOException("nope")).whenComplete((result, error) -> {}); | ||
|
|
||
| assertThat(terminations).hasValue(0); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a future failed by a task throwing, so the error is wrapped in a {@link | ||
| * java.util.concurrent.CompletionException} exactly as it would be in production and doesn't pass | ||
| * through {@link SafeFuture#completeExceptionally(Throwable)}. | ||
| */ | ||
| private SafeFuture<Void> failedWith(final Throwable error) { | ||
| return SafeFuture.COMPLETE.thenRun( | ||
| () -> { | ||
| throw new AssertionError("wrapper", error); | ||
| }); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
problem is that if the action itself throws it is possible we don't intercept that.
seems like all patterns following the functions\consumers should be wrapped in a try\catch
Then apply the same try/catch + checkForFatalError(t) pattern to exceptionally, handle, and handleAsync, and switch whenException / whenSuccess to go through whenComplete.
Also add checkForFatalError(t); before result.completeExceptionally(t) in handleComposed.
gpt is also suggesting to have something like:
and then use that like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense, updating
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tbenr all feedback addressed in d54affc