From 0a3a8784283329d3a374c601fa302f8409f902f1 Mon Sep 17 00:00:00 2001 From: Jason Lowe Date: Fri, 2 Mar 2018 09:59:46 -0600 Subject: [PATCH] YARN-7511. NPE in ContainerLocalizer when localization failed for running container. Contributed by Tao Yang (cherry picked from commit 83798f15f8602ef580a7885876de114b2425da89) --- .../localizer/ResourceSet.java | 4 +++ .../container/TestContainer.java | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ResourceSet.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ResourceSet.java index 5914f92cdac..0096f5448e9 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ResourceSet.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/localizer/ResourceSet.java @@ -138,6 +138,10 @@ public class ResourceSet { } public void resourceLocalizationFailed(LocalResourceRequest request) { + // Skip null request when localization failed for running container + if (request == null) { + return; + } pendingResources.remove(request); resourcesFailedToBeLocalized.add(request); } diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/TestContainer.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/TestContainer.java index 64e6cf0b0fc..3b34a878ad5 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/TestContainer.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/TestContainer.java @@ -378,6 +378,27 @@ public class TestContainer { } } + @Test + @SuppressWarnings("unchecked") + public void testLocalizationFailureWhileRunning() + throws Exception { + WrappedContainer wc = null; + try { + wc = new WrappedContainer(6, 314159265358979L, 4344, "yak"); + wc.initContainer(); + wc.localizeResources(); + wc.launchContainer(); + reset(wc.localizerBus); + assertEquals(ContainerState.RUNNING, wc.c.getContainerState()); + // Now in RUNNING, handle ContainerResourceFailedEvent, cause NPE before + wc.handleContainerResourceFailedEvent(); + } finally { + if (wc != null) { + wc.finished(); + } + } + } + @Test @SuppressWarnings("unchecked") // mocked generic public void testCleanupOnKillRequest() throws Exception { @@ -1132,6 +1153,11 @@ public class TestContainer { drainDispatcherEvents(); } + public void handleContainerResourceFailedEvent() { + c.handle(new ContainerResourceFailedEvent(cId, null, null)); + drainDispatcherEvents(); + } + // Localize resources // Skip some resources so as to consider them failed public Map> doLocalizeResources(