You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2020/03/15 11:37:42 UTC

[GitHub] [flink] azagrebin opened a new pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

azagrebin opened a new pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408
 
 
   The direct and Metaspace OOM error messages are quite confusing for users.
   This PR suggests to improve them for most cases in fatal error handler of TM and direct memory segment allocation. The added messages explain the possible error reasons and ways to resolve them.
   
   In case of Metaspace OOM error, we try a graceful TM shutdown to notify JM because it is not expected to require class loading for that and cause further failures.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395649146
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentFactory.java
 ##########
 @@ -32,6 +36,7 @@
  */
 @Internal
 public final class MemorySegmentFactory {
 
 Review comment:
   Maybe it is a Github issue, but this commit should occur before 167df1ef2da294b747cf7fd03cc8314599c6b5a5.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-600217460
 
 
   Thanks for the review @tillrohrmann 
   
   As I understand, OOM can generally happen everywhere, especially Metaspace OOM on any class loading, not only in user code. Therefore, my idea was to try to catch it in common places, as you also mentioned, in the most outer exception handling of known threads or propagate errors to the common threads: 
   - task thread (user code loading or running, error handling)
   - TM RPC main thread (unhandled exceptions in RPC calls)
   - network threads
   
   I thought that handling in task thread is the most probable place to catch the error but you are right I can look into other places as well.
   
   If I do not miss something, `TaskExecutor#submitTask` does not look special comparing to other RPC handlers running in RPC main thread. RPC endpoint could have some central error handling place for this case or I overlooked it. I would assume that it does not make sense for RPC endpoint to survive OOM error but it makes sense to try reporting it at least to JM if possible, e.g. for Metaspace OOM.
   
   I can also write tests emulating throwing errors in those known threads and checking that `onFatalError` is properly called.
   
   By adding error message to the OOM exception, I suppose you mean either generating another one with new detailed message or wrapping it in another more descriptive OOM exception. This would have to be also done in the same places as logging atm. I somewhat did not want to touch the original error generated by JVM but I think you are right about reporting it to JM. I can change the error message of the error.
   
   For the case of `taskmanager.jvm-exit-on-oom`, indeed, I overlooked that. The error message can be also improved.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395643017
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/runtime/util/ExceptionUtilsITCases.java
 ##########
 @@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.flink.runtime.util;
+
+import org.apache.flink.test.util.TestProcessBuilder;
+import org.apache.flink.test.util.TestProcessBuilder.TestProcess;
+import org.apache.flink.testutils.ClassLoaderUtils;
+import org.apache.flink.testutils.ClassLoaderUtils.ClassLoaderBuilder;
+import org.apache.flink.util.ExceptionUtils;
+
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryPoolMXBean;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for {@link  ExceptionUtils} which require to spawn JVM process and set JVM memory args.
+ */
+public class ExceptionUtilsITCases {
+	private static final long INITIAL_BIG_METASPACE_SIZE = 128 * (1 << 20); // 128Mb
+
+	@ClassRule
+	public static final TemporaryFolder TEMPORARY_FOLDER = new TemporaryFolder();
+
+	@Test
+	public void testIsMetaspaceOutOfMemoryError() throws IOException, InterruptedException {
+		// load only one class and record required Metaspace
+		long okMetaspace = Long.parseLong(run(1, INITIAL_BIG_METASPACE_SIZE));
+		// load more classes to cause 'OutOfMemoryError: Metaspace'
+		assertThat(run(1000, okMetaspace), is(""));
+	}
+
+	private static String run(int numberOfLoadedClasses, long metaspaceSize) throws InterruptedException, IOException {
+		TestProcessBuilder taskManagerProcessBuilder = new TestProcessBuilder(DummyClassLoadingProgram.class.getName());
+		taskManagerProcessBuilder.addJvmArg("-XX:-UseCompressedOops");
+		taskManagerProcessBuilder.addJvmArg(String.format("-XX:MaxMetaspaceSize=%d", metaspaceSize));
+		taskManagerProcessBuilder.addMainClassArg(Integer.toString(numberOfLoadedClasses));
+		taskManagerProcessBuilder.addMainClassArg(TEMPORARY_FOLDER.getRoot().getAbsolutePath());
+		TestProcess p = taskManagerProcessBuilder.start();
+		p.getProcess().waitFor();
+		assertThat(p.getErrorOutput().toString().trim(), is(""));
+		return p.getProcessOutput().toString().trim();
+	}
+
+	/**
+	 * Dummy java program to generate Metaspace OOM.
+	 */
+	public static class DummyClassLoadingProgram {
+		private DummyClassLoadingProgram() {
+		}
+
+		public static void main(String[] args) {
+			// trigger needed classes loaded
+			output("");
+			ExceptionUtils.isMetaspaceOutOfMemoryError(new Exception());
+
+			Collection<Class<?>> classes = new ArrayList<>();
+			int numberOfLoadedClasses = Integer.parseInt(args[0]);
+			//noinspection OverlyBroadCatchBlock
 
 Review comment:
   Same here.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154103703",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6423",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154156428",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6453",
       "triggerID" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154275887",
       "triggerID" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "triggerType" : "PUSH"
     }, {
       "hash" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "status" : "FAILURE",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154293865",
       "triggerID" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "triggerType" : "PUSH"
     }, {
       "hash" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6457",
       "triggerID" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 033a5f5a7a43c083dea05cc281a89b5a177d51a7 Travis: [FAILURE](https://travis-ci.com/github/flink-ci/flink/builds/154293865) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6457) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154103703",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6423",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154156428",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6453",
       "triggerID" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154275887",
       "triggerID" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "triggerType" : "PUSH"
     }, {
       "hash" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154293865",
       "triggerID" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "triggerType" : "PUSH"
     }, {
       "hash" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6457",
       "triggerID" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 033a5f5a7a43c083dea05cc281a89b5a177d51a7 Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/154293865) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6457) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154103703",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6423",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154156428",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6453",
       "triggerID" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154275887",
       "triggerID" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "triggerType" : "PUSH"
     }, {
       "hash" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154293865",
       "triggerID" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "triggerType" : "PUSH"
     }, {
       "hash" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6457",
       "triggerID" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "triggerType" : "PUSH"
     }, {
       "hash" : "184b4b67bfa32778db927c74c24df80875244330",
       "status" : "SUCCESS",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6538",
       "triggerID" : "184b4b67bfa32778db927c74c24df80875244330",
       "triggerType" : "PUSH"
     }, {
       "hash" : "184b4b67bfa32778db927c74c24df80875244330",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154607058",
       "triggerID" : "184b4b67bfa32778db927c74c24df80875244330",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 184b4b67bfa32778db927c74c24df80875244330 Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/154607058) Azure: [SUCCESS](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6538) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395647271
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/runtime/util/ExceptionUtilsITCases.java
 ##########
 @@ -113,10 +168,10 @@ private static long getMetaspaceUsage() {
 			}
 			throw new RuntimeException("Metaspace usage is not found");
 		}
+	}
 
-		private static void output(String text) {
-			//noinspection UseOfSystemOutOrSystemErr
-			System.out.println(text);
-		}
+	private static void output(String text) {
+		//noinspection UseOfSystemOutOrSystemErr
 
 Review comment:
   Please remove.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-600217460
 
 
   Thanks for the review @tillrohrmann 
   
   As I understand, OOM can generally happen everywhere, especially Metaspace OOM on any class loading, not only in user code. Therefore, my idea was to try to catch it in common places, as you also mentioned, in the most outer exception handling of known threads or propagate errors to the common threads: 
   - task thread
   - RPC endpoint thread
   - network threads
   
   I thought that handling in task thread is the most probable place to catch the error but you are right I can look into other places as well.
   
   If I do not miss something, `TaskExecutor#submitTask` does not look special comparing to other RPC handlers running in RPC main thread. RPC endpoint could have some central error handling place for this case or I overlooked it. I would assume that it does not make sense for RPC endpoint to survive OOM error but at least to report it to JVM if possible.
   
   I can also write tests emulating throwing errors in those known threads and checking that `onFatalError` is properly called.
   
   By adding error message to the OOM exception, I suppose you mean either generating another one with now detailed message or wrapping it in another more descriptive OOM exception. This would have to be also done in the same places as logging atm. I somewhat did not want to touch the original error generated by JVM but I think you are right about reporting it to JM. I can change the error message of the error.
   
   For the case of `taskmanager.jvm-exit-on-oom: true`, indeed, I overlooked that. The error message can be also improved. Actually, `onFatalError` API could maybe additionally take a parameter saying how to terminate JVM.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r393874481
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
 ##########
 @@ -109,6 +131,26 @@ public static boolean isJvmFatalOrOutOfMemoryError(Throwable t) {
 		return isJvmFatalError(t) || t instanceof OutOfMemoryError;
 	}
 
+	/**
+	 * Checks whether the given exception indicates a JVM metaspace out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the metaspace {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isMetaspaceOutOfMemoryError(Throwable t) {
+		return t instanceof OutOfMemoryError && t.getMessage().startsWith("Metaspace");
+	}
 
 Review comment:
   Good question.
   I have not found any other ways to do it using some Java API.
   The message is documented though, e.g. in Oracle Java [8](https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/memleaks002.html) and [11](https://docs.oracle.com/en/java/javase/11/troubleshoot/troubleshoot-memory-leaks.html#GUID-19F6D28E-75A1-4480-9879-D0932B2F305B).

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154103703",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6423",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154156428",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6453",
       "triggerID" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154275887",
       "triggerID" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "triggerType" : "PUSH"
     }, {
       "hash" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "status" : "FAILURE",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154293865",
       "triggerID" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "triggerType" : "PUSH"
     }, {
       "hash" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6457",
       "triggerID" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "triggerType" : "PUSH"
     }, {
       "hash" : "184b4b67bfa32778db927c74c24df80875244330",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6538",
       "triggerID" : "184b4b67bfa32778db927c74c24df80875244330",
       "triggerType" : "PUSH"
     }, {
       "hash" : "184b4b67bfa32778db927c74c24df80875244330",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154607058",
       "triggerID" : "184b4b67bfa32778db927c74c24df80875244330",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 033a5f5a7a43c083dea05cc281a89b5a177d51a7 Travis: [FAILURE](https://travis-ci.com/github/flink-ci/flink/builds/154293865) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6457) 
   * 184b4b67bfa32778db927c74c24df80875244330 Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/154607058) Azure: [PENDING](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6538) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395640140
 
 

 ##########
 File path: flink-runtime/src/main/java/org/apache/flink/runtime/taskexecutor/TaskManagerRunner.java
 ##########
 @@ -246,9 +246,11 @@ public void start() throws Exception {
 
 	@Override
 	public void onFatalError(Throwable exception) {
-		LOG.error("Fatal error occurred while executing the TaskManager. Shutting it down...", exception);
+		Throwable enrichedException = ExceptionUtils.enrichTaskManagerOutOfMemoryError(exception);
+		LOG.error("Fatal error occurred while executing the TaskManager. Shutting it down...", enrichedException);
 
-		if (ExceptionUtils.isJvmFatalOrOutOfMemoryError(exception)) {
+		if (ExceptionUtils.isJvmFatalOrOutOfMemoryError(enrichedException) &&
+				!ExceptionUtils.isMetaspaceOutOfMemoryError(enrichedException)) {
 
 Review comment:
   Maybe add a comment explaining why it is ok to not fail hard in case of a metaspace OOM.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot commented on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot commented on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599199082
 
 
   Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
   to review your pull request. We will use this comment to track the progress of the review.
   
   
   ## Automated Checks
   Last check on commit 4614b57fc5790f02e874a3e60e34c0c1e0fbefe0 (Sun Mar 15 11:40:48 UTC 2020)
   
   **Warnings:**
    * No documentation files were touched! Remember to keep the Flink docs up to date!
   
   
   <sub>Mention the bot in a comment to re-run the automated checks.</sub>
   ## Review Progress
   
   * ❓ 1. The [description] looks good.
   * ❓ 2. There is [consensus] that the contribution should go into to Flink.
   * ❓ 3. Needs [attention] from.
   * ❓ 4. The change fits into the overall [architecture].
   * ❓ 5. Overall code [quality] is good.
   
   Please see the [Pull Request Review Guide](https://flink.apache.org/contributing/reviewing-prs.html) for a full explanation of the review process.<details>
    The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot approve description` to approve one or more aspects (aspects: `description`, `consensus`, `architecture` and `quality`)
    - `@flinkbot approve all` to approve all aspects
    - `@flinkbot approve-until architecture` to approve everything until `architecture`
    - `@flinkbot attention @username1 [@username2 ..]` to require somebody's attention
    - `@flinkbot disapprove architecture` to remove an approval you gave earlier
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395750790
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/runtime/util/ExceptionUtilsITCases.java
 ##########
 @@ -42,31 +45,83 @@
  * Tests for {@link  ExceptionUtils} which require to spawn JVM process and set JVM memory args.
  */
 public class ExceptionUtilsITCases {
+	private static final int DIRECT_MEMORY_SIZE = 1 << 20; // 128Mb
 
 Review comment:
   The comment is wrong, it is actually 1Mb. I can make it even 10Kb but it does not really affect the runtime too much, at least locally.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395645586
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/test/recovery/ProcessFailureCancelingITCase.java
 ##########
 @@ -237,11 +237,11 @@ public Long map(Long value) throws Exception {
 			// all seems well :-)
 		}
 		catch (Exception e) {
-			printProcessLog("TaskManager", taskManagerProcess.getOutput().toString());
+			printProcessLog("TaskManager", taskManagerProcess.getErrorOutput().toString());
 			throw e;
 		}
 		catch (Error e) {
-			printProcessLog("TaskManager 1", taskManagerProcess.getOutput().toString());
+			printProcessLog("TaskManager 1", taskManagerProcess.getErrorOutput().toString());
 
 Review comment:
   Same here, are we logging to stderr?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395748563
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/test/recovery/AbstractTaskManagerProcessFailureRecoveryTest.java
 ##########
 @@ -258,7 +258,7 @@ protected static void printProcessLog(String processName, TestProcess process) {
 			System.out.println("-----------------------------------------");
 			System.out.println(" BEGIN SPAWNED PROCESS LOG FOR " + processName);
 			System.out.println("-----------------------------------------");
-			System.out.println(process.getOutput().toString());
+			System.out.println(process.getErrorOutput().toString());
 
 Review comment:
   I suppose this test initially needed the stderr in case of error.
   `TestProcess#getOutput` function name was confusing as it actually contained `Process#getErrorStream` of the underlying process in `TestProcessBuilder#start`. Now I also needed to expose the normal stdout so I decided to change the naming.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395587622
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
 ##########
 @@ -109,6 +131,26 @@ public static boolean isJvmFatalOrOutOfMemoryError(Throwable t) {
 		return isJvmFatalError(t) || t instanceof OutOfMemoryError;
 	}
 
+	/**
+	 * Checks whether the given exception indicates a JVM metaspace out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the metaspace {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isMetaspaceOutOfMemoryError(Throwable t) {
+		return t instanceof OutOfMemoryError && t.getMessage().startsWith("Metaspace");
+	}
+
+	/**
+	 * Checks whether the given exception indicates a JVM direct out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the direct {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isDirectOutOfMemoryError(Throwable t) {
+		return t instanceof OutOfMemoryError && t.getMessage().startsWith("Direct buffer memory");
+	}
 
 Review comment:
   Direct OOM error assumption is much easier to check. I do not see any problems with it.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395748563
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/test/recovery/AbstractTaskManagerProcessFailureRecoveryTest.java
 ##########
 @@ -258,7 +258,7 @@ protected static void printProcessLog(String processName, TestProcess process) {
 			System.out.println("-----------------------------------------");
 			System.out.println(" BEGIN SPAWNED PROCESS LOG FOR " + processName);
 			System.out.println("-----------------------------------------");
-			System.out.println(process.getOutput().toString());
+			System.out.println(process.getErrorOutput().toString());
 
 Review comment:
   I suppose all these tests initially needed the stderr in case of error.
   `TestProcess#getOutput` function name was confusing as it actually contained `Process#getErrorStream` of the underlying process in `TestProcessBuilder#start`. Now I also needed to expose the normal stdout so I decided to change the naming.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395651866
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
 ##########
 @@ -109,6 +131,59 @@ public static boolean isJvmFatalOrOutOfMemoryError(Throwable t) {
 		return isJvmFatalError(t) || t instanceof OutOfMemoryError;
 	}
 
+	/**
+	 * Generates new {@link OutOfMemoryError} with more detailed message.
+	 *
+	 * <p>This method improves error message for direct and metaspace {@link OutOfMemoryError}.
+	 * It adds description of possible causes and ways of resolution.
+	 *
+	 * @param exception The exception to enrich.
+	 * @return either enriched exception if needed or the original one.
+	 */
+	public static Throwable enrichTaskManagerOutOfMemoryError(Throwable exception) {
+		if (isMetaspaceOutOfMemoryError(exception)) {
+			return changeOutOfMemoryErrorMessage(exception, TM_METASPACE_OOM_ERROR_MESSAGE);
+		} else if (isDirectOutOfMemoryError(exception)) {
+			return changeOutOfMemoryErrorMessage(exception, TM_DIRECT_OOM_ERROR_MESSAGE);
+		}
+		return exception;
+	}
+
+	private static OutOfMemoryError changeOutOfMemoryErrorMessage(Throwable exception, String newMessage) {
 
 Review comment:
   Maybe a test ensuring that the result is the same as `exception` modulo the message. What happens if `exception` is a subclass of `OutOfMemoryError`?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r393875544
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
 ##########
 @@ -109,6 +131,26 @@ public static boolean isJvmFatalOrOutOfMemoryError(Throwable t) {
 		return isJvmFatalError(t) || t instanceof OutOfMemoryError;
 	}
 
+	/**
+	 * Checks whether the given exception indicates a JVM metaspace out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the metaspace {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isMetaspaceOutOfMemoryError(Throwable t) {
+		return t instanceof OutOfMemoryError && t.getMessage().startsWith("Metaspace");
+	}
+
+	/**
+	 * Checks whether the given exception indicates a JVM direct out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the direct {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isDirectOutOfMemoryError(Throwable t) {
+		return t instanceof OutOfMemoryError && t.getMessage().startsWith("Direct buffer memory");
+	}
 
 Review comment:
   Again, I have not found any other ways to do it using some Java API.
   It is thrown with this message in Java 8 and 11 from `java.nio.Bits#reserveMemory`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-600217460
 
 
   Thanks for the review @tillrohrmann 
   
   As I understand, OOM can generally happen everywhere, especially Metaspace OOM on any class loading, not only in user code. Therefore, my idea was to try to catch it in common places, as you also mentioned, in the most outer exception handling of known threads or propagate errors to the common threads: 
   - task thread
   - TM RPC main thread
   - network threads
   
   I thought that handling in task thread is the most probable place to catch the error but you are right I can look into other places as well.
   
   If I do not miss something, `TaskExecutor#submitTask` does not look special comparing to other RPC handlers running in RPC main thread. RPC endpoint could have some central error handling place for this case or I overlooked it. I would assume that it does not make sense for RPC endpoint to survive OOM error but it makes sense to try reporting it at least to JM if possible, e.g. for Metaspace OOM.
   
   I can also write tests emulating throwing errors in those known threads and checking that `onFatalError` is properly called.
   
   By adding error message to the OOM exception, I suppose you mean either generating another one with new detailed message or wrapping it in another more descriptive OOM exception. This would have to be also done in the same places as logging atm. I somewhat did not want to touch the original error generated by JVM but I think you are right about reporting it to JM. I can change the error message of the error.
   
   For the case of `taskmanager.jvm-exit-on-oom`, indeed, I overlooked that. The error message can be also improved.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395762376
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
 ##########
 @@ -109,6 +131,59 @@ public static boolean isJvmFatalOrOutOfMemoryError(Throwable t) {
 		return isJvmFatalError(t) || t instanceof OutOfMemoryError;
 	}
 
+	/**
+	 * Generates new {@link OutOfMemoryError} with more detailed message.
+	 *
+	 * <p>This method improves error message for direct and metaspace {@link OutOfMemoryError}.
+	 * It adds description of possible causes and ways of resolution.
+	 *
+	 * @param exception The exception to enrich.
+	 * @return either enriched exception if needed or the original one.
+	 */
+	public static Throwable enrichTaskManagerOutOfMemoryError(Throwable exception) {
+		if (isMetaspaceOutOfMemoryError(exception)) {
+			return changeOutOfMemoryErrorMessage(exception, TM_METASPACE_OOM_ERROR_MESSAGE);
+		} else if (isDirectOutOfMemoryError(exception)) {
+			return changeOutOfMemoryErrorMessage(exception, TM_DIRECT_OOM_ERROR_MESSAGE);
+		}
+		return exception;
+	}
+
+	private static OutOfMemoryError changeOutOfMemoryErrorMessage(Throwable exception, String newMessage) {
+		Preconditions.checkArgument(exception instanceof OutOfMemoryError);
+		if (exception.getMessage().equals(newMessage)) {
+			return (OutOfMemoryError) exception;
+		}
+		OutOfMemoryError newError = new OutOfMemoryError(newMessage);
+		newError.initCause(exception.getCause());
+		newError.setStackTrace(exception.getStackTrace());
+		return newError;
+	}
+
+	/**
+	 * Checks whether the given exception indicates a JVM metaspace out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the metaspace {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isMetaspaceOutOfMemoryError(Throwable t) {
+		return isOutOfMemoryErrorWithMessageStartingWith(t, "Metaspace");
 
 Review comment:
   True, I thought about it. Currently, we do not do it in other fatal error checks. For this implementation, it will be difficult to rewrap it in the middle of the chain as it is immutable. We could change it to the wrapping approach in this case by creating a new exception with a cause which is the current chain. Not sure, whether this complication is needed atm as it has not been introduced for the existing checks. We could also add it later if it becomes a problem. AFAIK, it is also not recommended to wrap fatal errors in java but it is not guaranteed, of course.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot commented on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot commented on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 4614b57fc5790f02e874a3e60e34c0c1e0fbefe0 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * a453d434607e7cf03e334a990e42a807fb3065f2 Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/153718697) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 4614b57fc5790f02e874a3e60e34c0c1e0fbefe0 Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/153468294) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-600217460
 
 
   Thanks for the review @tillrohrmann 
   
   As I understand, OOM can generally happen everywhere, especially Metaspace OOM on any class loading, not only in user code. Therefore, my idea was to try to catch it in common places, as you also mentioned, in the most outer exception handling of known threads or propagated to them: 
   - task thread
   - RPC endpoint thread
   - network threads
   
   I thought that handling in task thread is the most probable place to catch the error but you are right I can look into other places as well.
   
   If I do not miss something, `TaskExecutor#submitTask` does not look special comparing to other RPC handlers running in RPC main thread. RPC endpoint could have some central error handling place for this case or I overlooked it. I would assume that it does not make sense for RPC endpoint to survive OOM error but at least to report it to JVM if possible.
   
   I can also write tests emulating throwing errors in those known threads and checking that `onFatalError` is properly called.
   
   By adding error message to the OOM exception, I suppose you mean either generating another one with now detailed message or wrapping it in another more descriptive OOM exception. This would have to be also done in the same places as logging atm. I somewhat did not want to touch the original error generated by JVM but I think you are right about reporting it to JM. I can change the error message of the error.
   
   For the case of `taskmanager.jvm-exit-on-oom: true`, indeed, I overlooked that. The error message can be also improved. Actually, `onFatalError` API could maybe additionally take a parameter saying how to terminate JVM.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395646139
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/runtime/util/ExceptionUtilsITCases.java
 ##########
 @@ -42,31 +45,83 @@
  * Tests for {@link  ExceptionUtils} which require to spawn JVM process and set JVM memory args.
  */
 public class ExceptionUtilsITCases {
+	private static final int DIRECT_MEMORY_SIZE = 1 << 20; // 128Mb
 
 Review comment:
   Can we make this size smaller?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395647124
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/runtime/util/ExceptionUtilsITCases.java
 ##########
 @@ -42,31 +45,83 @@
  * Tests for {@link  ExceptionUtils} which require to spawn JVM process and set JVM memory args.
  */
 public class ExceptionUtilsITCases {
+	private static final int DIRECT_MEMORY_SIZE = 1 << 20; // 128Mb
+	private static final int DIRECT_MEMORY_ALLOCATION_PAGE_SIZE = 1024; // 1Kb
+	private static final int DIRECT_MEMORY_PAGE_NUMBER = DIRECT_MEMORY_SIZE / DIRECT_MEMORY_ALLOCATION_PAGE_SIZE;
 	private static final long INITIAL_BIG_METASPACE_SIZE = 128 * (1 << 20); // 128Mb
 
 	@ClassRule
 	public static final TemporaryFolder TEMPORARY_FOLDER = new TemporaryFolder();
 
+	@Test
+	public void testIsDirectOutOfMemoryError() throws IOException, InterruptedException {
+		String className = DummyDirectAllocatingProgram.class.getName();
+		String out = run(className, Collections.emptyList(), DIRECT_MEMORY_SIZE, -1);
+		assertThat(out, is(""));
+	}
+
 	@Test
 	public void testIsMetaspaceOutOfMemoryError() throws IOException, InterruptedException {
+		String className = DummyClassLoadingProgram.class.getName();
 		// load only one class and record required Metaspace
-		long okMetaspace = Long.parseLong(run(1, INITIAL_BIG_METASPACE_SIZE));
+		String normalOut = run(className, getDummyClassLoadingProgramArgs(1), -1, INITIAL_BIG_METASPACE_SIZE);
+		long okMetaspace = Long.parseLong(normalOut);
 		// load more classes to cause 'OutOfMemoryError: Metaspace'
-		assertThat(run(1000, okMetaspace), is(""));
+		String oomOut = run(className, getDummyClassLoadingProgramArgs(1000), -1, okMetaspace);
+		assertThat(oomOut, is(""));
 	}
 
-	private static String run(int numberOfLoadedClasses, long metaspaceSize) throws InterruptedException, IOException {
-		TestProcessBuilder taskManagerProcessBuilder = new TestProcessBuilder(DummyClassLoadingProgram.class.getName());
-		taskManagerProcessBuilder.addJvmArg("-XX:-UseCompressedOops");
-		taskManagerProcessBuilder.addJvmArg(String.format("-XX:MaxMetaspaceSize=%d", metaspaceSize));
-		taskManagerProcessBuilder.addMainClassArg(Integer.toString(numberOfLoadedClasses));
-		taskManagerProcessBuilder.addMainClassArg(TEMPORARY_FOLDER.getRoot().getAbsolutePath());
+	private static String run(
+			String className,
+			Iterable<String> args,
+			long directMemorySize,
+			long metaspaceSize) throws InterruptedException, IOException {
+		TestProcessBuilder taskManagerProcessBuilder = new TestProcessBuilder(className);
+		if (directMemorySize > 0) {
+			taskManagerProcessBuilder.addJvmArg(String.format("-XX:MaxDirectMemorySize=%d", directMemorySize));
+		}
+		if (metaspaceSize > 0) {
+			taskManagerProcessBuilder.addJvmArg("-XX:-UseCompressedOops");
+			taskManagerProcessBuilder.addJvmArg(String.format("-XX:MaxMetaspaceSize=%d", metaspaceSize));
+		}
+		for (String arg : args) {
+			taskManagerProcessBuilder.addMainClassArg(arg);
+		}
 		TestProcess p = taskManagerProcessBuilder.start();
 		p.getProcess().waitFor();
 		assertThat(p.getErrorOutput().toString().trim(), is(""));
 		return p.getProcessOutput().toString().trim();
 	}
 
+	private static Collection<String> getDummyClassLoadingProgramArgs(int numberOfLoadedClasses) {
+		return Arrays.asList(
+			Integer.toString(numberOfLoadedClasses),
+			TEMPORARY_FOLDER.getRoot().getAbsolutePath());
+	}
+
+	/**
+	 * Dummy java program to generate Direct OOM.
+	 */
+	public static class DummyDirectAllocatingProgram {
 
 Review comment:
   ```suggestion
   	public static class DummyDirectMemoryAllocatingProgram {
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "FAILURE",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154103703",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 077a6f3d6f7457325e98aedbabe61c3e7ab18c3d Travis: [FAILURE](https://travis-ci.com/github/flink-ci/flink/builds/154103703) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-600217460
 
 
   Thanks for the review @tillrohrmann 
   
   As I understand, OOM can generally happen everywhere, especially Metaspace OOM on any class loading, not only in user code. Therefore, my idea was to try to catch it in common places, as you also mentioned, in the most outer exception handling of known threads or propagate errors to the common threads: 
   - task thread (user code loading or running, error handling)
   - TM RPC main thread
   - network threads
   
   I thought that handling in task thread is the most probable place to catch the error but you are right I can look into other places as well.
   
   If I do not miss something, `TaskExecutor#submitTask` does not look special comparing to other RPC handlers running in RPC main thread. RPC endpoint could have some central error handling place for this case or I overlooked it. I would assume that it does not make sense for RPC endpoint to survive OOM error but it makes sense to try reporting it at least to JM if possible, e.g. for Metaspace OOM.
   
   I can also write tests emulating throwing errors in those known threads and checking that `onFatalError` is properly called.
   
   By adding error message to the OOM exception, I suppose you mean either generating another one with new detailed message or wrapping it in another more descriptive OOM exception. This would have to be also done in the same places as logging atm. I somewhat did not want to touch the original error generated by JVM but I think you are right about reporting it to JM. I can change the error message of the error.
   
   For the case of `taskmanager.jvm-exit-on-oom`, indeed, I overlooked that. The error message can be also improved.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395645257
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/test/recovery/AbstractTaskManagerProcessFailureRecoveryTest.java
 ##########
 @@ -258,7 +258,7 @@ protected static void printProcessLog(String processName, TestProcess process) {
 			System.out.println("-----------------------------------------");
 			System.out.println(" BEGIN SPAWNED PROCESS LOG FOR " + processName);
 			System.out.println("-----------------------------------------");
-			System.out.println(process.getOutput().toString());
+			System.out.println(process.getErrorOutput().toString());
 
 Review comment:
   Why is this change ok? Is the log being logged to stderr?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395641907
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/runtime/util/ExceptionUtilsITCases.java
 ##########
 @@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.flink.runtime.util;
+
+import org.apache.flink.test.util.TestProcessBuilder;
+import org.apache.flink.test.util.TestProcessBuilder.TestProcess;
+import org.apache.flink.testutils.ClassLoaderUtils;
+import org.apache.flink.testutils.ClassLoaderUtils.ClassLoaderBuilder;
+import org.apache.flink.util.ExceptionUtils;
+
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryPoolMXBean;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for {@link  ExceptionUtils} which require to spawn JVM process and set JVM memory args.
+ */
+public class ExceptionUtilsITCases {
+	private static final long INITIAL_BIG_METASPACE_SIZE = 128 * (1 << 20); // 128Mb
 
 Review comment:
   Could we make this size a bit smaller? I would assume that a couple of MBs could be enough.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-600217460
 
 
   Thanks for the review @tillrohrmann 
   
   As I understand, OOM can generally happen everywhere, especially Metaspace OOM on any class loading, not only in user code. Therefore, my idea was to try to catch it in common places, as you also mentioned, in the most outer exception handling of known threads or propagate errors to the common threads: 
   - task thread
   - TM RPC main thread
   - network threads
   
   I thought that handling in task thread is the most probable place to catch the error but you are right I can look into other places as well.
   
   If I do not miss something, `TaskExecutor#submitTask` does not look special comparing to other RPC handlers running in RPC main thread. RPC endpoint could have some central error handling place for this case or I overlooked it. I would assume that it does not make sense for RPC endpoint to survive OOM error but it makes sense to try reporting it at least to JM if possible.
   
   I can also write tests emulating throwing errors in those known threads and checking that `onFatalError` is properly called.
   
   By adding error message to the OOM exception, I suppose you mean either generating another one with now detailed message or wrapping it in another more descriptive OOM exception. This would have to be also done in the same places as logging atm. I somewhat did not want to touch the original error generated by JVM but I think you are right about reporting it to JM. I can change the error message of the error.
   
   For the case of `taskmanager.jvm-exit-on-oom: true`, indeed, I overlooked that. The error message can be also improved. Actually, `onFatalError` API could maybe additionally take a parameter saying how to terminate JVM.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] zhijiangW commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
zhijiangW commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r394328761
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentFactory.java
 ##########
 @@ -94,7 +99,15 @@ public static MemorySegment allocateUnpooledOffHeapMemory(int size) {
 	 * @return A new memory segment, backed by unpooled off-heap memory.
 	 */
 	public static MemorySegment allocateUnpooledOffHeapMemory(int size, Object owner) {
-		ByteBuffer memory = ByteBuffer.allocateDirect(size);
+		ByteBuffer memory;
+		try {
+			memory = ByteBuffer.allocateDirect(size);
+		} catch (OutOfMemoryError e) {
+			if (ExceptionUtils.isDirectOutOfMemoryError(e)) {
+				LOG.error(ExceptionUtils.TM_DIRECT_OOM_ERROR_MESSAGE, e);
+			}
+			throw e;
+		}
 
 Review comment:
   > But if the receiver sees the exception, then the user will see it in the logs, right?
   Yes.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395762376
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
 ##########
 @@ -109,6 +131,59 @@ public static boolean isJvmFatalOrOutOfMemoryError(Throwable t) {
 		return isJvmFatalError(t) || t instanceof OutOfMemoryError;
 	}
 
+	/**
+	 * Generates new {@link OutOfMemoryError} with more detailed message.
+	 *
+	 * <p>This method improves error message for direct and metaspace {@link OutOfMemoryError}.
+	 * It adds description of possible causes and ways of resolution.
+	 *
+	 * @param exception The exception to enrich.
+	 * @return either enriched exception if needed or the original one.
+	 */
+	public static Throwable enrichTaskManagerOutOfMemoryError(Throwable exception) {
+		if (isMetaspaceOutOfMemoryError(exception)) {
+			return changeOutOfMemoryErrorMessage(exception, TM_METASPACE_OOM_ERROR_MESSAGE);
+		} else if (isDirectOutOfMemoryError(exception)) {
+			return changeOutOfMemoryErrorMessage(exception, TM_DIRECT_OOM_ERROR_MESSAGE);
+		}
+		return exception;
+	}
+
+	private static OutOfMemoryError changeOutOfMemoryErrorMessage(Throwable exception, String newMessage) {
+		Preconditions.checkArgument(exception instanceof OutOfMemoryError);
+		if (exception.getMessage().equals(newMessage)) {
+			return (OutOfMemoryError) exception;
+		}
+		OutOfMemoryError newError = new OutOfMemoryError(newMessage);
+		newError.initCause(exception.getCause());
+		newError.setStackTrace(exception.getStackTrace());
+		return newError;
+	}
+
+	/**
+	 * Checks whether the given exception indicates a JVM metaspace out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the metaspace {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isMetaspaceOutOfMemoryError(Throwable t) {
+		return isOutOfMemoryErrorWithMessageStartingWith(t, "Metaspace");
 
 Review comment:
   True, I thought about it. Currently, we do not do it in other fatal error checks. For this implementation, it will be difficult to rewrap it in the middle of the chain as it is immutable. We could change it to the wrapping approach in this case by creating a new exception with a cause which is the current chain. It is not a very big change but not sure, whether this is needed atm as it has not been introduced for the existing checks. We could also add it later if it becomes a problem. AFAIK, it is also not recommended to wrap fatal errors in java but it is not guaranteed, of course.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] zhijiangW commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
zhijiangW commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r394111632
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentFactory.java
 ##########
 @@ -94,7 +99,15 @@ public static MemorySegment allocateUnpooledOffHeapMemory(int size) {
 	 * @return A new memory segment, backed by unpooled off-heap memory.
 	 */
 	public static MemorySegment allocateUnpooledOffHeapMemory(int size, Object owner) {
-		ByteBuffer memory = ByteBuffer.allocateDirect(size);
+		ByteBuffer memory;
+		try {
+			memory = ByteBuffer.allocateDirect(size);
+		} catch (OutOfMemoryError e) {
+			if (ExceptionUtils.isDirectOutOfMemoryError(e)) {
+				LOG.error(ExceptionUtils.TM_DIRECT_OOM_ERROR_MESSAGE, e);
+			}
+			throw e;
+		}
 
 Review comment:
   Some inputs from my side: there are two usages for `allocateUnpooledOffHeapMemory` ATM.
   
   - One is for initializing `NetworkBufferPool` in `TaskManagerServices`, and it also explicitly handles the `OutOfMemoryError` message inside. Maybe we also want to unify the message there.
   
   - Another is for reading blocking partitions for batch jobs on upstream side, which is triggered by netty stack. This error would not be thrown outsides to be visible in task stack, and be only transported to the downstream side via network to cause the respective task failure. It also makes sense to handle this special error on upstream side, to make processor exit if possible. Otherwise the same error might happen again after failover recovery.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395653523
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
 ##########
 @@ -109,6 +131,59 @@ public static boolean isJvmFatalOrOutOfMemoryError(Throwable t) {
 		return isJvmFatalError(t) || t instanceof OutOfMemoryError;
 	}
 
+	/**
+	 * Generates new {@link OutOfMemoryError} with more detailed message.
+	 *
+	 * <p>This method improves error message for direct and metaspace {@link OutOfMemoryError}.
+	 * It adds description of possible causes and ways of resolution.
+	 *
+	 * @param exception The exception to enrich.
+	 * @return either enriched exception if needed or the original one.
+	 */
+	public static Throwable enrichTaskManagerOutOfMemoryError(Throwable exception) {
+		if (isMetaspaceOutOfMemoryError(exception)) {
+			return changeOutOfMemoryErrorMessage(exception, TM_METASPACE_OOM_ERROR_MESSAGE);
+		} else if (isDirectOutOfMemoryError(exception)) {
+			return changeOutOfMemoryErrorMessage(exception, TM_DIRECT_OOM_ERROR_MESSAGE);
+		}
+		return exception;
+	}
+
+	private static OutOfMemoryError changeOutOfMemoryErrorMessage(Throwable exception, String newMessage) {
+		Preconditions.checkArgument(exception instanceof OutOfMemoryError);
+		if (exception.getMessage().equals(newMessage)) {
+			return (OutOfMemoryError) exception;
+		}
+		OutOfMemoryError newError = new OutOfMemoryError(newMessage);
+		newError.initCause(exception.getCause());
+		newError.setStackTrace(exception.getStackTrace());
+		return newError;
+	}
+
+	/**
+	 * Checks whether the given exception indicates a JVM metaspace out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the metaspace {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isMetaspaceOutOfMemoryError(Throwable t) {
+		return isOutOfMemoryErrorWithMessageStartingWith(t, "Metaspace");
 
 Review comment:
   Something to consider: It could also happen that `t` contains a metaspace OOM further down in the cause chain and not as a top-level exception.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * a453d434607e7cf03e334a990e42a807fb3065f2 Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/153718697) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333) 
   * 7a317b3796df35687a4e99f796207876c99b2c81 Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/154091120) Azure: [PENDING](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "FAILURE",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 7a317b3796df35687a4e99f796207876c99b2c81 Travis: [FAILURE](https://travis-ci.com/github/flink-ci/flink/builds/154091120) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409) 
   * 077a6f3d6f7457325e98aedbabe61c3e7ab18c3d UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "FAILURE",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154103703",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6423",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154156428",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 077a6f3d6f7457325e98aedbabe61c3e7ab18c3d Travis: [FAILURE](https://travis-ci.com/github/flink-ci/flink/builds/154103703) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417) 
   * 167df1ef2da294b747cf7fd03cc8314599c6b5a5 Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/154156428) Azure: [PENDING](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6423) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r396347458
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
 ##########
 @@ -109,6 +131,59 @@ public static boolean isJvmFatalOrOutOfMemoryError(Throwable t) {
 		return isJvmFatalError(t) || t instanceof OutOfMemoryError;
 	}
 
+	/**
+	 * Generates new {@link OutOfMemoryError} with more detailed message.
+	 *
+	 * <p>This method improves error message for direct and metaspace {@link OutOfMemoryError}.
+	 * It adds description of possible causes and ways of resolution.
+	 *
+	 * @param exception The exception to enrich.
+	 * @return either enriched exception if needed or the original one.
+	 */
+	public static Throwable enrichTaskManagerOutOfMemoryError(Throwable exception) {
+		if (isMetaspaceOutOfMemoryError(exception)) {
+			return changeOutOfMemoryErrorMessage(exception, TM_METASPACE_OOM_ERROR_MESSAGE);
+		} else if (isDirectOutOfMemoryError(exception)) {
+			return changeOutOfMemoryErrorMessage(exception, TM_DIRECT_OOM_ERROR_MESSAGE);
+		}
+		return exception;
+	}
+
+	private static OutOfMemoryError changeOutOfMemoryErrorMessage(Throwable exception, String newMessage) {
+		Preconditions.checkArgument(exception instanceof OutOfMemoryError);
+		if (exception.getMessage().equals(newMessage)) {
+			return (OutOfMemoryError) exception;
+		}
+		OutOfMemoryError newError = new OutOfMemoryError(newMessage);
+		newError.initCause(exception.getCause());
+		newError.setStackTrace(exception.getStackTrace());
+		return newError;
+	}
+
+	/**
+	 * Checks whether the given exception indicates a JVM metaspace out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the metaspace {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isMetaspaceOutOfMemoryError(Throwable t) {
+		return isOutOfMemoryErrorWithMessageStartingWith(t, "Metaspace");
+	}
+
+	/**
+	 * Checks whether the given exception indicates a JVM direct out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the direct {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isDirectOutOfMemoryError(Throwable t) {
+		return isOutOfMemoryErrorWithMessageStartingWith(t, "Direct buffer memory");
+	}
+
+	private static boolean isOutOfMemoryErrorWithMessageStartingWith(Throwable t, String prefix) {
+		return t.getClass() == OutOfMemoryError.class && t.getMessage() != null && t.getMessage().startsWith(prefix);
 
 Review comment:
   Maybe add a comment stating that we check for class equality in order to not catch subclasses.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395587291
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
 ##########
 @@ -109,6 +131,26 @@ public static boolean isJvmFatalOrOutOfMemoryError(Throwable t) {
 		return isJvmFatalError(t) || t instanceof OutOfMemoryError;
 	}
 
+	/**
+	 * Checks whether the given exception indicates a JVM metaspace out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the metaspace {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isMetaspaceOutOfMemoryError(Throwable t) {
+		return t instanceof OutOfMemoryError && t.getMessage().startsWith("Metaspace");
+	}
 
 Review comment:
   I added the Metaspace assumption test. It is a bit tricky to make sure and load all the classes to measure the Metaspace usage so that OOM error is thrown in expected class loading. It was stable locally. If this ever leads to an instability or you also have more doubts, I can remove the commit.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395645386
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/test/recovery/ProcessFailureCancelingITCase.java
 ##########
 @@ -237,11 +237,11 @@ public Long map(Long value) throws Exception {
 			// all seems well :-)
 		}
 		catch (Exception e) {
-			printProcessLog("TaskManager", taskManagerProcess.getOutput().toString());
+			printProcessLog("TaskManager", taskManagerProcess.getErrorOutput().toString());
 
 Review comment:
   Same here with the change. Why is it ok?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-600520719
 
 
   I think you are right that OOMs can happen everywhere and we won't most likely cover all susceptible places with this PR. But this is also ok I believe. The goal of this PR should be to setup a common framework how to handle these exceptions and how to tell the user about it. Once we have this, it is matter of finding the most problematic places and to add the respective handling logic. With setting up a framework I mean to have a long term vision how things should eventually work.
   
   ### How do we want to react to OOMs in general?
   
   In order to answer this question I believe we need to distinguish between the different types of OOMs (heap, direct memory, metaspace) and where they are happening (user code, framework).
   
   I believe that this point is out of scope for this PR but is still important in order to evolve Flink into the right direction.
   
   #### Framework
   
   At the moment we don't handle OOMs in the framework consistently. Sometimes we call the `FatalErrorHandler` and sometimes we simply return the OOM as a response to RPCs.
   
   I think it would be safest to fail the process if an OOM occurs within the framework, because it is hard to guarantee that the framework is still in a consistent state.
   
   One question could be whether we want to treat different OOMs differently. For example, continuing in case of metaspace OOM. This might be an optimization but in the first version I would be in favour of treating OOMs all the same way.
   
   #### User code
   
   At the moment, we treat OOMs as user code failures unless `taskmanager.jvm-exit-on-oom` has been set to true. In the latter case, we exit the JVM hard.
   
   If there is a OOM originating from user code, the least we need to do is to fail the task. I think one can make cases for either killing the process or not. If the task failed because it exceeded the direct memory limit, then other tasks might not be affected by it. On the other hand, there should always be an option to tell Flink to fail the process in case of OOMs.
   
   Maybe a robust solution would be to fail the process by default and allow to turn it off.
   
   ### What do we want to tell the user?
   
   For certain errors, we want to provide better error messages pointing the user towards a potential solution. This warrants for a general facility to add additional diagnostics to an exception. Maybe one could introduce `ExceptionUtils#enrichErrorMessage` which takes an exception and enriches the error message. Alternatively, we could have `ExceptionUtils#logDiagnostics`.
   
   ### Where do we react?
   
   Usually, error handling should be done on the level where the error is recoverable or where it leaves the component (before sending it to another component). In the case of OOMs occurring in the context of the framework, we are talking about the fatal error handler. In order to treat OOMs consistently across RPCs and method which directly calling the fatal error handler, we might need to extend the `RpcEndpoint` to allow passing in a `FatalErrorHandler`.
   
   For user code exceptions, the natural fit would be the `Task#doRun` where we react to user code exceptions and fail the task. One thing to add here is that if we trade the user code OOM as non-fatal, then it would also be good to enrich the error message of the exception we are sending to the JM where it is also logged. This would be an argument for wrapping the original exception/enriching the exception message instead of logging some statements wrt the exception.  
   
   So what I would suggest to do for this PR is to cover user code OOMs. It could be as easy as wrapping the user code exception with a more meaningful error message/enriching the error message and making sure that it is logged in a way we want it to happen.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395652754
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
 ##########
 @@ -109,6 +131,59 @@ public static boolean isJvmFatalOrOutOfMemoryError(Throwable t) {
 		return isJvmFatalError(t) || t instanceof OutOfMemoryError;
 	}
 
+	/**
+	 * Generates new {@link OutOfMemoryError} with more detailed message.
+	 *
+	 * <p>This method improves error message for direct and metaspace {@link OutOfMemoryError}.
+	 * It adds description of possible causes and ways of resolution.
+	 *
+	 * @param exception The exception to enrich.
+	 * @return either enriched exception if needed or the original one.
+	 */
+	public static Throwable enrichTaskManagerOutOfMemoryError(Throwable exception) {
+		if (isMetaspaceOutOfMemoryError(exception)) {
+			return changeOutOfMemoryErrorMessage(exception, TM_METASPACE_OOM_ERROR_MESSAGE);
+		} else if (isDirectOutOfMemoryError(exception)) {
+			return changeOutOfMemoryErrorMessage(exception, TM_DIRECT_OOM_ERROR_MESSAGE);
+		}
+		return exception;
+	}
+
+	private static OutOfMemoryError changeOutOfMemoryErrorMessage(Throwable exception, String newMessage) {
 
 Review comment:
   Maybe we should only change the message iff `exception.getClass() == OutOfMemoryError.class`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395744227
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/runtime/util/ExceptionUtilsITCases.java
 ##########
 @@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.flink.runtime.util;
+
+import org.apache.flink.test.util.TestProcessBuilder;
+import org.apache.flink.test.util.TestProcessBuilder.TestProcess;
+import org.apache.flink.testutils.ClassLoaderUtils;
+import org.apache.flink.testutils.ClassLoaderUtils.ClassLoaderBuilder;
+import org.apache.flink.util.ExceptionUtils;
+
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryPoolMXBean;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for {@link  ExceptionUtils} which require to spawn JVM process and set JVM memory args.
+ */
+public class ExceptionUtilsITCases {
+	private static final long INITIAL_BIG_METASPACE_SIZE = 128 * (1 << 20); // 128Mb
 
 Review comment:
   Sure, any value less than 10Mb is unstable according to my local experiments on mac os. I can set to 32Mb. The default value is anyways unlimited. Though I do not know whether JVM will actually preallocate the Metaspace according to the limit.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * a453d434607e7cf03e334a990e42a807fb3065f2 Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/153718697) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154103703",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6423",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154156428",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6453",
       "triggerID" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "status" : "FAILURE",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154275887",
       "triggerID" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * dea1ff5122b0ad0b2058406da9257f6dfbe39193 Travis: [FAILURE](https://travis-ci.com/github/flink-ci/flink/builds/154275887) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6453) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395650523
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/runtime/util/ExceptionUtilsITCases.java
 ##########
 @@ -0,0 +1,177 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.flink.runtime.util;
+
+import org.apache.flink.test.util.TestProcessBuilder;
+import org.apache.flink.test.util.TestProcessBuilder.TestProcess;
+import org.apache.flink.testutils.ClassLoaderUtils;
+import org.apache.flink.testutils.ClassLoaderUtils.ClassLoaderBuilder;
+import org.apache.flink.util.ExceptionUtils;
+
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryPoolMXBean;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for {@link  ExceptionUtils} which require to spawn JVM process and set JVM memory args.
+ */
+public class ExceptionUtilsITCases {
+	private static final int DIRECT_MEMORY_SIZE = 1 << 20; // 128Mb
+	private static final int DIRECT_MEMORY_ALLOCATION_PAGE_SIZE = 1024; // 1Kb
+	private static final int DIRECT_MEMORY_PAGE_NUMBER = DIRECT_MEMORY_SIZE / DIRECT_MEMORY_ALLOCATION_PAGE_SIZE;
+	private static final long INITIAL_BIG_METASPACE_SIZE = 128 * (1 << 20); // 128Mb
+
+	@ClassRule
+	public static final TemporaryFolder TEMPORARY_FOLDER = new TemporaryFolder();
+
+	@Test
+	public void testIsDirectOutOfMemoryError() throws IOException, InterruptedException {
+		String className = DummyDirectAllocatingProgram.class.getName();
+		String out = run(className, Collections.emptyList(), DIRECT_MEMORY_SIZE, -1);
+		assertThat(out, is(""));
+	}
+
+	@Test
+	public void testIsMetaspaceOutOfMemoryError() throws IOException, InterruptedException {
+		String className = DummyClassLoadingProgram.class.getName();
+		// load only one class and record required Metaspace
+		String normalOut = run(className, getDummyClassLoadingProgramArgs(1), -1, INITIAL_BIG_METASPACE_SIZE);
+		long okMetaspace = Long.parseLong(normalOut);
+		// load more classes to cause 'OutOfMemoryError: Metaspace'
+		String oomOut = run(className, getDummyClassLoadingProgramArgs(1000), -1, okMetaspace);
+		assertThat(oomOut, is(""));
+	}
+
+	private static String run(
+			String className,
+			Iterable<String> args,
+			long directMemorySize,
+			long metaspaceSize) throws InterruptedException, IOException {
+		TestProcessBuilder taskManagerProcessBuilder = new TestProcessBuilder(className);
+		if (directMemorySize > 0) {
+			taskManagerProcessBuilder.addJvmArg(String.format("-XX:MaxDirectMemorySize=%d", directMemorySize));
+		}
+		if (metaspaceSize > 0) {
+			taskManagerProcessBuilder.addJvmArg("-XX:-UseCompressedOops");
+			taskManagerProcessBuilder.addJvmArg(String.format("-XX:MaxMetaspaceSize=%d", metaspaceSize));
+		}
+		for (String arg : args) {
+			taskManagerProcessBuilder.addMainClassArg(arg);
+		}
+		TestProcess p = taskManagerProcessBuilder.start();
+		p.getProcess().waitFor();
+		assertThat(p.getErrorOutput().toString().trim(), is(""));
+		return p.getProcessOutput().toString().trim();
+	}
+
+	private static Collection<String> getDummyClassLoadingProgramArgs(int numberOfLoadedClasses) {
+		return Arrays.asList(
+			Integer.toString(numberOfLoadedClasses),
+			TEMPORARY_FOLDER.getRoot().getAbsolutePath());
+	}
+
+	/**
+	 * Dummy java program to generate Direct OOM.
+	 */
+	public static class DummyDirectAllocatingProgram {
+		private DummyDirectAllocatingProgram() {
+		}
+
+		public static void main(String[] args) {
+			Collection<ByteBuffer> buffers = new ArrayList<>();
+			try {
+				for (int page = 0; page < 2 * DIRECT_MEMORY_PAGE_NUMBER; page++) {
+					buffers.add(ByteBuffer.allocateDirect(DIRECT_MEMORY_ALLOCATION_PAGE_SIZE));
+				}
+			} catch (Throwable t) {
+				if (!ExceptionUtils.isDirectOutOfMemoryError(t)) {
+					output("Wrong exception: " + t);
+				}
+				return;
+			}
+			output("buffers: " + buffers);
 
 Review comment:
   Can this call be moved inside of the `try` block directly after the for loop?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "FAILURE",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 7a317b3796df35687a4e99f796207876c99b2c81 Travis: [FAILURE](https://travis-ci.com/github/flink-ci/flink/builds/154091120) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-600217460
 
 
   Thanks for the review @tillrohrmann 
   
   As I understand, OOM can generally happen everywhere, especially Metaspace OOM on any class loading, not only in user code. Therefore, my idea was to try to catch it in common places, as you also mentioned, in the most outer exception handling of known threads or propagate errors to the common threads: 
   - task thread
   - TM RPC main thread
   - network threads
   
   I thought that handling in task thread is the most probable place to catch the error but you are right I can look into other places as well.
   
   If I do not miss something, `TaskExecutor#submitTask` does not look special comparing to other RPC handlers running in RPC main thread. RPC endpoint could have some central error handling place for this case or I overlooked it. I would assume that it does not make sense for RPC endpoint to survive OOM error but at least to report it to JVM if possible.
   
   I can also write tests emulating throwing errors in those known threads and checking that `onFatalError` is properly called.
   
   By adding error message to the OOM exception, I suppose you mean either generating another one with now detailed message or wrapping it in another more descriptive OOM exception. This would have to be also done in the same places as logging atm. I somewhat did not want to touch the original error generated by JVM but I think you are right about reporting it to JM. I can change the error message of the error.
   
   For the case of `taskmanager.jvm-exit-on-oom: true`, indeed, I overlooked that. The error message can be also improved. Actually, `onFatalError` API could maybe additionally take a parameter saying how to terminate JVM.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin closed pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin closed pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 7a317b3796df35687a4e99f796207876c99b2c81 Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/154091120) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r394162959
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentFactory.java
 ##########
 @@ -94,7 +99,15 @@ public static MemorySegment allocateUnpooledOffHeapMemory(int size) {
 	 * @return A new memory segment, backed by unpooled off-heap memory.
 	 */
 	public static MemorySegment allocateUnpooledOffHeapMemory(int size, Object owner) {
-		ByteBuffer memory = ByteBuffer.allocateDirect(size);
+		ByteBuffer memory;
+		try {
+			memory = ByteBuffer.allocateDirect(size);
+		} catch (OutOfMemoryError e) {
+			if (ExceptionUtils.isDirectOutOfMemoryError(e)) {
+				LOG.error(ExceptionUtils.TM_DIRECT_OOM_ERROR_MESSAGE, e);
+			}
+			throw e;
+		}
 
 Review comment:
   But if the receiver sees the exception, then the user will see it in the logs, right? This is what we want to achieve here. Making the sender handle the exception (e.g. shutting down or so) could then be a separate issue.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r394161827
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
 ##########
 @@ -109,6 +131,26 @@ public static boolean isJvmFatalOrOutOfMemoryError(Throwable t) {
 		return isJvmFatalError(t) || t instanceof OutOfMemoryError;
 	}
 
+	/**
+	 * Checks whether the given exception indicates a JVM metaspace out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the metaspace {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isMetaspaceOutOfMemoryError(Throwable t) {
+		return t instanceof OutOfMemoryError && t.getMessage().startsWith("Metaspace");
+	}
+
+	/**
+	 * Checks whether the given exception indicates a JVM direct out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the direct {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isDirectOutOfMemoryError(Throwable t) {
+		return t instanceof OutOfMemoryError && t.getMessage().startsWith("Direct buffer memory");
+	}
 
 Review comment:
   I think we need to guard these assumptions.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r393778126
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
 ##########
 @@ -109,6 +131,26 @@ public static boolean isJvmFatalOrOutOfMemoryError(Throwable t) {
 		return isJvmFatalError(t) || t instanceof OutOfMemoryError;
 	}
 
+	/**
+	 * Checks whether the given exception indicates a JVM metaspace out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the metaspace {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isMetaspaceOutOfMemoryError(Throwable t) {
+		return t instanceof OutOfMemoryError && t.getMessage().startsWith("Metaspace");
+	}
+
+	/**
+	 * Checks whether the given exception indicates a JVM direct out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the direct {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isDirectOutOfMemoryError(Throwable t) {
+		return t instanceof OutOfMemoryError && t.getMessage().startsWith("Direct buffer memory");
+	}
 
 Review comment:
   How reliable is this test across different JVM implementations?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r393879723
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentFactory.java
 ##########
 @@ -94,7 +99,15 @@ public static MemorySegment allocateUnpooledOffHeapMemory(int size) {
 	 * @return A new memory segment, backed by unpooled off-heap memory.
 	 */
 	public static MemorySegment allocateUnpooledOffHeapMemory(int size, Object owner) {
-		ByteBuffer memory = ByteBuffer.allocateDirect(size);
+		ByteBuffer memory;
+		try {
+			memory = ByteBuffer.allocateDirect(size);
+		} catch (OutOfMemoryError e) {
+			if (ExceptionUtils.isDirectOutOfMemoryError(e)) {
+				LOG.error(ExceptionUtils.TM_DIRECT_OOM_ERROR_MESSAGE, e);
+			}
+			throw e;
+		}
 
 Review comment:
   I was not sure whether this will always get into the Task thread error handling, sometimes it is called in Netty channel read handlers. I can do more research on it. Maybe, @zhijiangW has a quick good idea. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154103703",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 077a6f3d6f7457325e98aedbabe61c3e7ab18c3d Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/154103703) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r393778080
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
 ##########
 @@ -109,6 +131,26 @@ public static boolean isJvmFatalOrOutOfMemoryError(Throwable t) {
 		return isJvmFatalError(t) || t instanceof OutOfMemoryError;
 	}
 
+	/**
+	 * Checks whether the given exception indicates a JVM metaspace out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the metaspace {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isMetaspaceOutOfMemoryError(Throwable t) {
+		return t instanceof OutOfMemoryError && t.getMessage().startsWith("Metaspace");
+	}
 
 Review comment:
   How reliable is this test across different JVM implementations?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * a453d434607e7cf03e334a990e42a807fb3065f2 Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/153718697) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333) 
   * 7a317b3796df35687a4e99f796207876c99b2c81 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-600217460
 
 
   Thanks for the review @tillrohrmann 
   
   As I understand, OOM can generally happen everywhere, especially Metaspace OOM on any class loading, not only in user code. Therefore, my idea was to try to catch it in common places, as you also mentioned, in the most outer exception handling of known threads or propagate errors to the common threads: 
   - task thread
   - TM RPC main thread
   - network threads
   
   I thought that handling in task thread is the most probable place to catch the error but you are right I can look into other places as well.
   
   If I do not miss something, `TaskExecutor#submitTask` does not look special comparing to other RPC handlers running in RPC main thread. RPC endpoint could have some central error handling place for this case or I overlooked it. I would assume that it does not make sense for RPC endpoint to survive OOM error but it makes sense to try reporting it at least to JM if possible, e.g. for Metaspace OOM.
   
   I can also write tests emulating throwing errors in those known threads and checking that `onFatalError` is properly called.
   
   By adding error message to the OOM exception, I suppose you mean either generating another one with new detailed message or wrapping it in another more descriptive OOM exception. This would have to be also done in the same places as logging atm. I somewhat did not want to touch the original error generated by JVM but I think you are right about reporting it to JM. I can change the error message of the error.
   
   For the case of `taskmanager.jvm-exit-on-oom`, indeed, I overlooked that. The error message can be also improved. Actually, `onFatalError` API may additionally take a parameter saying how to terminate JVM.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395642927
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/runtime/util/ExceptionUtilsITCases.java
 ##########
 @@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.flink.runtime.util;
+
+import org.apache.flink.test.util.TestProcessBuilder;
+import org.apache.flink.test.util.TestProcessBuilder.TestProcess;
+import org.apache.flink.testutils.ClassLoaderUtils;
+import org.apache.flink.testutils.ClassLoaderUtils.ClassLoaderBuilder;
+import org.apache.flink.util.ExceptionUtils;
+
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryPoolMXBean;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for {@link  ExceptionUtils} which require to spawn JVM process and set JVM memory args.
+ */
+public class ExceptionUtilsITCases {
+	private static final long INITIAL_BIG_METASPACE_SIZE = 128 * (1 << 20); // 128Mb
+
+	@ClassRule
+	public static final TemporaryFolder TEMPORARY_FOLDER = new TemporaryFolder();
+
+	@Test
+	public void testIsMetaspaceOutOfMemoryError() throws IOException, InterruptedException {
+		// load only one class and record required Metaspace
+		long okMetaspace = Long.parseLong(run(1, INITIAL_BIG_METASPACE_SIZE));
+		// load more classes to cause 'OutOfMemoryError: Metaspace'
+		assertThat(run(1000, okMetaspace), is(""));
+	}
+
+	private static String run(int numberOfLoadedClasses, long metaspaceSize) throws InterruptedException, IOException {
+		TestProcessBuilder taskManagerProcessBuilder = new TestProcessBuilder(DummyClassLoadingProgram.class.getName());
+		taskManagerProcessBuilder.addJvmArg("-XX:-UseCompressedOops");
+		taskManagerProcessBuilder.addJvmArg(String.format("-XX:MaxMetaspaceSize=%d", metaspaceSize));
+		taskManagerProcessBuilder.addMainClassArg(Integer.toString(numberOfLoadedClasses));
+		taskManagerProcessBuilder.addMainClassArg(TEMPORARY_FOLDER.getRoot().getAbsolutePath());
+		TestProcess p = taskManagerProcessBuilder.start();
+		p.getProcess().waitFor();
+		assertThat(p.getErrorOutput().toString().trim(), is(""));
+		return p.getProcessOutput().toString().trim();
+	}
+
+	/**
+	 * Dummy java program to generate Metaspace OOM.
+	 */
+	public static class DummyClassLoadingProgram {
+		private DummyClassLoadingProgram() {
+		}
+
+		public static void main(String[] args) {
+			// trigger needed classes loaded
+			output("");
+			ExceptionUtils.isMetaspaceOutOfMemoryError(new Exception());
+
+			Collection<Class<?>> classes = new ArrayList<>();
+			int numberOfLoadedClasses = Integer.parseInt(args[0]);
+			//noinspection OverlyBroadCatchBlock
+			try {
+				for (int index = 0; index < numberOfLoadedClasses; index++) {
+					classes.add(loadDummyClass(index, args[1]));
+				}
+				String out = classes.size() > 1 ? "Exception is not thrown, metaspace usage: " : "";
+				output(out + getMetaspaceUsage());
+			} catch (Throwable t) {
+				if (ExceptionUtils.isMetaspaceOutOfMemoryError(t)) {
+					return;
+				}
+				output("Wrong exception: " + t);
+			}
+		}
+
+		private static Class<?> loadDummyClass(int index, String folderToSaveSource) throws ClassNotFoundException, IOException {
+			String className = "DummyClass" + index;
+			String sourcePattern = "public class %s { @Override public String toString() { return \"%s\"; } }";
+			ClassLoaderBuilder classLoaderBuilder = ClassLoaderUtils.withRoot(new File(folderToSaveSource));
+			classLoaderBuilder.addClass(className, String.format(sourcePattern, className, "dummy"));
+			ClassLoader classLoader = classLoaderBuilder.build();
+			return Class.forName(className, true, classLoader);
+		}
+
+		private static long getMetaspaceUsage() {
+			for (MemoryPoolMXBean memoryMXBean : ManagementFactory.getMemoryPoolMXBeans()) {
+				if ("Metaspace".equals(memoryMXBean.getName())) {
+					return memoryMXBean.getUsage().getUsed();
+				}
+			}
+			throw new RuntimeException("Metaspace usage is not found");
+		}
+
+		private static void output(String text) {
+			//noinspection UseOfSystemOutOrSystemErr
 
 Review comment:
   Please remove. This is specific to your IDE setup.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154103703",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6423",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "FAILURE",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154156428",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 167df1ef2da294b747cf7fd03cc8314599c6b5a5 Travis: [FAILURE](https://travis-ci.com/github/flink-ci/flink/builds/154156428) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6423) 
   * dea1ff5122b0ad0b2058406da9257f6dfbe39193 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395643722
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/runtime/util/ExceptionUtilsITCases.java
 ##########
 @@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.flink.runtime.util;
+
+import org.apache.flink.test.util.TestProcessBuilder;
+import org.apache.flink.test.util.TestProcessBuilder.TestProcess;
+import org.apache.flink.testutils.ClassLoaderUtils;
+import org.apache.flink.testutils.ClassLoaderUtils.ClassLoaderBuilder;
+import org.apache.flink.util.ExceptionUtils;
+
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryPoolMXBean;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for {@link  ExceptionUtils} which require to spawn JVM process and set JVM memory args.
+ */
+public class ExceptionUtilsITCases {
+	private static final long INITIAL_BIG_METASPACE_SIZE = 128 * (1 << 20); // 128Mb
+
+	@ClassRule
+	public static final TemporaryFolder TEMPORARY_FOLDER = new TemporaryFolder();
+
+	@Test
+	public void testIsMetaspaceOutOfMemoryError() throws IOException, InterruptedException {
+		// load only one class and record required Metaspace
+		long okMetaspace = Long.parseLong(run(1, INITIAL_BIG_METASPACE_SIZE));
+		// load more classes to cause 'OutOfMemoryError: Metaspace'
+		assertThat(run(1000, okMetaspace), is(""));
+	}
+
+	private static String run(int numberOfLoadedClasses, long metaspaceSize) throws InterruptedException, IOException {
+		TestProcessBuilder taskManagerProcessBuilder = new TestProcessBuilder(DummyClassLoadingProgram.class.getName());
+		taskManagerProcessBuilder.addJvmArg("-XX:-UseCompressedOops");
+		taskManagerProcessBuilder.addJvmArg(String.format("-XX:MaxMetaspaceSize=%d", metaspaceSize));
+		taskManagerProcessBuilder.addMainClassArg(Integer.toString(numberOfLoadedClasses));
+		taskManagerProcessBuilder.addMainClassArg(TEMPORARY_FOLDER.getRoot().getAbsolutePath());
+		TestProcess p = taskManagerProcessBuilder.start();
+		p.getProcess().waitFor();
+		assertThat(p.getErrorOutput().toString().trim(), is(""));
+		return p.getProcessOutput().toString().trim();
+	}
+
+	/**
+	 * Dummy java program to generate Metaspace OOM.
+	 */
+	public static class DummyClassLoadingProgram {
+		private DummyClassLoadingProgram() {
+		}
+
+		public static void main(String[] args) {
+			// trigger needed classes loaded
 
 Review comment:
   ```suggestion
   			// triggers loading needed classes
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r394200928
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
 ##########
 @@ -109,6 +131,26 @@ public static boolean isJvmFatalOrOutOfMemoryError(Throwable t) {
 		return isJvmFatalError(t) || t instanceof OutOfMemoryError;
 	}
 
+	/**
+	 * Checks whether the given exception indicates a JVM metaspace out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the metaspace {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isMetaspaceOutOfMemoryError(Throwable t) {
+		return t instanceof OutOfMemoryError && t.getMessage().startsWith("Metaspace");
+	}
 
 Review comment:
   True, this should help

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395584885
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentFactory.java
 ##########
 @@ -94,7 +99,15 @@ public static MemorySegment allocateUnpooledOffHeapMemory(int size) {
 	 * @return A new memory segment, backed by unpooled off-heap memory.
 	 */
 	public static MemorySegment allocateUnpooledOffHeapMemory(int size, Object owner) {
-		ByteBuffer memory = ByteBuffer.allocateDirect(size);
+		ByteBuffer memory;
+		try {
+			memory = ByteBuffer.allocateDirect(size);
+		} catch (OutOfMemoryError e) {
+			if (ExceptionUtils.isDirectOutOfMemoryError(e)) {
+				LOG.error(ExceptionUtils.TM_DIRECT_OOM_ERROR_MESSAGE, e);
+			}
+			throw e;
+		}
 
 Review comment:
   I suggest we keep this change to address this reported problem [FLINK-15981](https://issues.apache.org/jira/browse/FLINK-15981) and log it on sender side until we establish a general error reporting for the sender. The error message, got by receiver, is also improved now in a separate commit.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154103703",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6423",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154156428",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6453",
       "triggerID" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154275887",
       "triggerID" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "triggerType" : "PUSH"
     }, {
       "hash" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "status" : "FAILURE",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154293865",
       "triggerID" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "triggerType" : "PUSH"
     }, {
       "hash" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6457",
       "triggerID" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "triggerType" : "PUSH"
     }, {
       "hash" : "184b4b67bfa32778db927c74c24df80875244330",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "184b4b67bfa32778db927c74c24df80875244330",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 033a5f5a7a43c083dea05cc281a89b5a177d51a7 Travis: [FAILURE](https://travis-ci.com/github/flink-ci/flink/builds/154293865) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6457) 
   * 184b4b67bfa32778db927c74c24df80875244330 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-601807299
 
 
   Thanks for the further review @tillrohrmann 
   I addressed the comments. Regarding OOM in the middle of the chain, see inline comment. 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "FAILURE",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154103703",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 7a317b3796df35687a4e99f796207876c99b2c81 Travis: [FAILURE](https://travis-ci.com/github/flink-ci/flink/builds/154091120) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409) 
   * 077a6f3d6f7457325e98aedbabe61c3e7ab18c3d Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/154103703) Azure: [PENDING](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-601657949
 
 
   Thanks for the explanation @tillrohrmann 
   
   I agree we can address other cases of failure handling separately and PR was supposed to focus on OOMs in user code loading and invocation in `Task#doRun`. The problem in PR was that as you mentioned, the `FatalErrorHandler` is called for user code failure case, only cleanup. I fixed this.
   
   I checked how it looks in logs with a [simple job](https://github.com/azagrebin/flink/commit/a09b077cc60c8c0194f2d2242f6352a8b7ac7915#diff-ec75df84b8550ffec1ac164ffb9c0909). Generating a real Metaspace OOM is tricky because depending on limit it really crashes in various places, including error handling itself.
   
   `taskmanager.jvm-exit-on-oom` is false by default. Do you think we should change this? I agree that different OOMs can differently affect other tasks but not sure about complicating logic more with options.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395755534
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentFactory.java
 ##########
 @@ -32,6 +36,7 @@
  */
 @Internal
 public final class MemorySegmentFactory {
 
 Review comment:
   it is a Github issue

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "PENDING",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 4614b57fc5790f02e874a3e60e34c0c1e0fbefe0 Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/153468294) 
   * a453d434607e7cf03e334a990e42a807fb3065f2 Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/153718697) Azure: [PENDING](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-600217460
 
 
   Thanks for the review @tillrohrmann 
   
   As I understand, OOM can generally happen everywhere, especially Metaspace OOM on any class loading, not only in user code. Therefore, my idea was to try to catch it in common places, as you also mentioned, in the most outer exception handling of known threads or propagate errors to the common threads: 
   - task thread
   - TM RPC main thread
   - network threads
   
   I thought that handling in task thread is the most probable place to catch the error but you are right I can look into other places as well.
   
   If I do not miss something, `TaskExecutor#submitTask` does not look special comparing to other RPC handlers running in RPC main thread. RPC endpoint could have some central error handling place for this case or I overlooked it. I would assume that it does not make sense for RPC endpoint to survive OOM error but it makes sense to try reporting it at least to JM if possible, e.g. for Metaspace OOM.
   
   I can also write tests emulating throwing errors in those known threads and checking that `onFatalError` is properly called.
   
   By adding error message to the OOM exception, I suppose you mean either generating another one with now detailed message or wrapping it in another more descriptive OOM exception. This would have to be also done in the same places as logging atm. I somewhat did not want to touch the original error generated by JVM but I think you are right about reporting it to JM. I can change the error message of the error.
   
   For the case of `taskmanager.jvm-exit-on-oom: true`, indeed, I overlooked that. The error message can be also improved. Actually, `onFatalError` API could maybe additionally take a parameter saying how to terminate JVM.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 4614b57fc5790f02e874a3e60e34c0c1e0fbefe0 Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/153468294) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "SUCCESS",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 4614b57fc5790f02e874a3e60e34c0c1e0fbefe0 Travis: [SUCCESS](https://travis-ci.com/github/flink-ci/flink/builds/153468294) 
   * a453d434607e7cf03e334a990e42a807fb3065f2 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-600217460
 
 
   Thanks for the review @tillrohrmann 
   
   As I understand, OOM can generally happen everywhere, especially Metaspace OOM on any class loading, not only in user code. Therefore, my idea was to try to catch it in common places, as you also mentioned, in the most outer exception handling of known threads or propagate errors to the common threads: 
   - task thread
   - TM RPC main thread
   - network threads
   
   I thought that handling in task thread is the most probable place to catch the error but you are right I can look into other places as well.
   
   If I do not miss something, `TaskExecutor#submitTask` does not look special comparing to other RPC handlers running in RPC main thread. RPC endpoint could have some central error handling place for this case or I overlooked it. I would assume that it does not make sense for RPC endpoint to survive OOM error but it makes sense to try reporting it at least to JM if possible, e.g. for Metaspace OOM.
   
   I can also write tests emulating throwing errors in those known threads and checking that `onFatalError` is properly called.
   
   By adding error message to the OOM exception, I suppose you mean either generating another one with new detailed message or wrapping it in another more descriptive OOM exception. This would have to be also done in the same places as logging atm. I somewhat did not want to touch the original error generated by JVM but I think you are right about reporting it to JM. I can change the error message of the error.
   
   For the case of `taskmanager.jvm-exit-on-oom`, indeed, I overlooked that. The error message can be also improved. Actually, `onFatalError` API could maybe additionally take a parameter saying how to terminate JVM.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "FAILURE",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154103703",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 077a6f3d6f7457325e98aedbabe61c3e7ab18c3d Travis: [FAILURE](https://travis-ci.com/github/flink-ci/flink/builds/154103703) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417) 
   * 167df1ef2da294b747cf7fd03cc8314599c6b5a5 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154103703",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6423",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154156428",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6453",
       "triggerID" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "triggerType" : "PUSH"
     }, {
       "hash" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "status" : "FAILURE",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154275887",
       "triggerID" : "dea1ff5122b0ad0b2058406da9257f6dfbe39193",
       "triggerType" : "PUSH"
     }, {
       "hash" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "033a5f5a7a43c083dea05cc281a89b5a177d51a7",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * dea1ff5122b0ad0b2058406da9257f6dfbe39193 Travis: [FAILURE](https://travis-ci.com/github/flink-ci/flink/builds/154275887) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6453) 
   * 033a5f5a7a43c083dea05cc281a89b5a177d51a7 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154103703",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6423",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "FAILURE",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154156428",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 167df1ef2da294b747cf7fd03cc8314599c6b5a5 Travis: [FAILURE](https://travis-ci.com/github/flink-ci/flink/builds/154156428) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6423) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-600217460
 
 
   Thanks for the review @tillrohrmann 
   
   As I understand, OOM can generally happen everywhere, especially Metaspace OOM on any class loading, not only in user code. Therefore, my idea was to try to catch it in common places, as you also mentioned, in the most outer exception handling of known threads or propagate errors to the common threads: 
   - task thread
   - TM RPC main thread
   - network threads
   
   I thought that handling in task thread is the most probable place to catch the error but you are right I can look into other places as well.
   
   If I do not miss something, `TaskExecutor#submitTask` does not look special comparing to other RPC handlers running in RPC main thread. RPC endpoint could have some central error handling place for this case or I overlooked it. I would assume that it does not make sense for RPC endpoint to survive OOM error but it makes sense to try reporting it at least to JM if possible, e.g. for Metaspace OOM.
   
   I can also write tests emulating throwing errors in those known threads and checking that `onFatalError` is properly called.
   
   By adding error message to the OOM exception, I suppose you mean either generating another one with new detailed message or wrapping it in another more descriptive OOM exception. This would have to be also done in the same places as logging atm. I somewhat did not want to touch the original error generated by JVM but I think you are right about reporting it to JM. I can change the error message of the error.
   
   For the case of `taskmanager.jvm-exit-on-oom: true`, indeed, I overlooked that. The error message can be also improved. Actually, `onFatalError` API could maybe additionally take a parameter saying how to terminate JVM.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
azagrebin commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r394208538
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentFactory.java
 ##########
 @@ -94,7 +99,15 @@ public static MemorySegment allocateUnpooledOffHeapMemory(int size) {
 	 * @return A new memory segment, backed by unpooled off-heap memory.
 	 */
 	public static MemorySegment allocateUnpooledOffHeapMemory(int size, Object owner) {
-		ByteBuffer memory = ByteBuffer.allocateDirect(size);
+		ByteBuffer memory;
+		try {
+			memory = ByteBuffer.allocateDirect(size);
+		} catch (OutOfMemoryError e) {
+			if (ExceptionUtils.isDirectOutOfMemoryError(e)) {
+				LOG.error(ExceptionUtils.TM_DIRECT_OOM_ERROR_MESSAGE, e);
+			}
+			throw e;
+		}
 
 Review comment:
   I agree, improving the error message of exception should also help here to report more details to the receiver.
   It would be nice to figure out a way to handle direct OOM errors from Netty threads in general because Netty also can allocate direct memory. Same for Netty threads in Akka RPC framework. These tasks can be follow-ups.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r394161655
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
 ##########
 @@ -109,6 +131,26 @@ public static boolean isJvmFatalOrOutOfMemoryError(Throwable t) {
 		return isJvmFatalError(t) || t instanceof OutOfMemoryError;
 	}
 
+	/**
+	 * Checks whether the given exception indicates a JVM metaspace out-of-memory error.
+	 *
+	 * @param t The exception to check.
+	 * @return True, if the exception is the metaspace {@link OutOfMemoryError}, false otherwise.
+	 */
+	public static boolean isMetaspaceOutOfMemoryError(Throwable t) {
+		return t instanceof OutOfMemoryError && t.getMessage().startsWith("Metaspace");
+	}
 
 Review comment:
   What about openjdk? Could we add tests for these assumption so that we are sure if you build and run the tests on your JVM, then these assumptions hold?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] zhijiangW commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
zhijiangW commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r394112080
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentFactory.java
 ##########
 @@ -94,7 +99,15 @@ public static MemorySegment allocateUnpooledOffHeapMemory(int size) {
 	 * @return A new memory segment, backed by unpooled off-heap memory.
 	 */
 	public static MemorySegment allocateUnpooledOffHeapMemory(int size, Object owner) {
-		ByteBuffer memory = ByteBuffer.allocateDirect(size);
+		ByteBuffer memory;
+		try {
+			memory = ByteBuffer.allocateDirect(size);
+		} catch (OutOfMemoryError e) {
+			if (ExceptionUtils.isDirectOutOfMemoryError(e)) {
+				LOG.error(ExceptionUtils.TM_DIRECT_OOM_ERROR_MESSAGE, e);
+			}
+			throw e;
+		}
 
 Review comment:
   For the second usage, it had a ticket (https://issues.apache.org/jira/browse/FLINK-15981) for improving this direct memory overhead,  not sure when will be done, just FYI.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] zhijiangW commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
zhijiangW commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r394328761
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentFactory.java
 ##########
 @@ -94,7 +99,15 @@ public static MemorySegment allocateUnpooledOffHeapMemory(int size) {
 	 * @return A new memory segment, backed by unpooled off-heap memory.
 	 */
 	public static MemorySegment allocateUnpooledOffHeapMemory(int size, Object owner) {
-		ByteBuffer memory = ByteBuffer.allocateDirect(size);
+		ByteBuffer memory;
+		try {
+			memory = ByteBuffer.allocateDirect(size);
+		} catch (OutOfMemoryError e) {
+			if (ExceptionUtils.isDirectOutOfMemoryError(e)) {
+				LOG.error(ExceptionUtils.TM_DIRECT_OOM_ERROR_MESSAGE, e);
+			}
+			throw e;
+		}
 
 Review comment:
   > But if the receiver sees the exception, then the user will see it in the logs, right?
   
   Yes.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r393771271
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/util/ExceptionUtils.java
 ##########
 @@ -48,6 +49,27 @@
 	/** The stringified representation of a null exception reference. */
 	public static final String STRINGIFIED_NULL_EXCEPTION = "(null)";
 
+	public static final String TM_DIRECT_OOM_ERROR_MESSAGE = String.format(
+			"The direct out-of-memory error has occurred. This can mean two things: either job(s) require(s) " +
+				"a larger size of JVM direct memory or there is a direct memory leak. The direct memory can be " +
+				"allocated by user code or some of its dependencies. In this case '%s' configuration option should be " +
+				"increased. Flink framework and its dependencies also consume the direct memory, mostly for network " +
+				"communication. The most of network memory is managed by Flink and should not result in out-of-memory " +
+				"error. In certain special cases, in particular for jobs with high parallelism, the framework may " +
+				"require more direct memory which is not managed by Flink. In this case '%s' configuration option " +
+				"should be increased. If the error persists then there is probably a direct memory leak which has to " +
+				"be investigated and fixed. The task executor has to be shutdown...",
+		TaskManagerOptions.TASK_OFF_HEAP_MEMORY.key(),
+		TaskManagerOptions.FRAMEWORK_OFF_HEAP_MEMORY.key());
+
+	public static final String TM_METASPACE_OOM_ERROR_MESSAGE = String.format(
+		"The metaspace out-of-memory error has occurred. This can mean two things: either job requires " +
 
 Review comment:
   ```suggestion
   		"The metaspace out-of-memory error has occurred. This can mean two things: either the job requires " +
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r395640974
 
 

 ##########
 File path: flink-tests/src/test/java/org/apache/flink/runtime/util/ExceptionUtilsITCases.java
 ##########
 @@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.flink.runtime.util;
+
+import org.apache.flink.test.util.TestProcessBuilder;
+import org.apache.flink.test.util.TestProcessBuilder.TestProcess;
+import org.apache.flink.testutils.ClassLoaderUtils;
+import org.apache.flink.testutils.ClassLoaderUtils.ClassLoaderBuilder;
+import org.apache.flink.util.ExceptionUtils;
+
+import org.junit.ClassRule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.lang.management.MemoryPoolMXBean;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for {@link  ExceptionUtils} which require to spawn JVM process and set JVM memory args.
+ */
+public class ExceptionUtilsITCases {
 
 Review comment:
   `extends TestLogger` is missing.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
tillrohrmann commented on a change in pull request #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#discussion_r393784214
 
 

 ##########
 File path: flink-core/src/main/java/org/apache/flink/core/memory/MemorySegmentFactory.java
 ##########
 @@ -94,7 +99,15 @@ public static MemorySegment allocateUnpooledOffHeapMemory(int size) {
 	 * @return A new memory segment, backed by unpooled off-heap memory.
 	 */
 	public static MemorySegment allocateUnpooledOffHeapMemory(int size, Object owner) {
-		ByteBuffer memory = ByteBuffer.allocateDirect(size);
+		ByteBuffer memory;
+		try {
+			memory = ByteBuffer.allocateDirect(size);
+		} catch (OutOfMemoryError e) {
+			if (ExceptionUtils.isDirectOutOfMemoryError(e)) {
+				LOG.error(ExceptionUtils.TM_DIRECT_OOM_ERROR_MESSAGE, e);
+			}
+			throw e;
+		}
 
 Review comment:
   Why do we need this special exception handling here? Wouldn't it be better if we let the exception bubble up and treat OOMs consistently in a single place (e.g. fatal error handler, or the entrypoint if this is an exception which occurs during initialization)?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [flink] flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling

Posted by GitBox <gi...@apache.org>.
flinkbot edited a comment on issue #11408: [FLINK-15989][FLINK-16225] Improve direct and metaspace out-of-memory error handling
URL: https://github.com/apache/flink/pull/11408#issuecomment-599442524
 
 
   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153468294",
       "triggerID" : "4614b57fc5790f02e874a3e60e34c0c1e0fbefe0",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6333",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/153718697",
       "triggerID" : "a453d434607e7cf03e334a990e42a807fb3065f2",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6409",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154091120",
       "triggerID" : "7a317b3796df35687a4e99f796207876c99b2c81",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154103703",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "status" : "DELETED",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6417",
       "triggerID" : "077a6f3d6f7457325e98aedbabe61c3e7ab18c3d",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "FAILURE",
       "url" : "https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6423",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     }, {
       "hash" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "status" : "PENDING",
       "url" : "https://travis-ci.com/github/flink-ci/flink/builds/154156428",
       "triggerID" : "167df1ef2da294b747cf7fd03cc8314599c6b5a5",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 167df1ef2da294b747cf7fd03cc8314599c6b5a5 Travis: [PENDING](https://travis-ci.com/github/flink-ci/flink/builds/154156428) Azure: [FAILURE](https://dev.azure.com/rmetzger/5bd3ef0a-4359-41af-abca-811b04098d2e/_build/results?buildId=6423) 
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run travis` re-run the last Travis build
    - `@flinkbot run azure` re-run the last Azure build
   </details>

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services