From 71430d8bbd8572b186096d86708e12e555b06830 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Fri, 21 Dec 2018 11:06:43 +0100 Subject: [PATCH] =?UTF-8?q?Call=20FastThreadLocal.removeAll()=20before=20n?= =?UTF-8?q?otify=20termination=20future=20of=20=E2=80=A6=20(#8666)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Motivation: We should try removing all FastThreadLocals for the Thread before we notify the termination. future. The user may block on the future and once it unblocks the JVM may terminate and start unloading classes. Modifications: Remove all FastThreadLocals for the Thread before notify termination future. Result: Fixes https://github.com/netty/netty/issues/6596. --- .../netty/util/concurrent/SingleThreadEventExecutor.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/io/netty/util/concurrent/SingleThreadEventExecutor.java b/common/src/main/java/io/netty/util/concurrent/SingleThreadEventExecutor.java index 994b961729..f11cc2ea62 100644 --- a/common/src/main/java/io/netty/util/concurrent/SingleThreadEventExecutor.java +++ b/common/src/main/java/io/netty/util/concurrent/SingleThreadEventExecutor.java @@ -911,6 +911,12 @@ public abstract class SingleThreadEventExecutor extends AbstractScheduledEventEx try { cleanup(); } finally { + // Lets remove all FastThreadLocals for the Thread as we are about to terminate and notify + // the future. The user may block on the future and once it unblocks the JVM may terminate + // and start unloading classes. + // See https://github.com/netty/netty/issues/6596. + FastThreadLocal.removeAll(); + STATE_UPDATER.set(SingleThreadEventExecutor.this, ST_TERMINATED); threadLock.release(); if (!taskQueue.isEmpty()) { @@ -919,7 +925,6 @@ public abstract class SingleThreadEventExecutor extends AbstractScheduledEventEx "non-empty task queue (" + taskQueue.size() + ')'); } } - terminationFuture.setSuccess(null); } }