From b7e947709ef28f0e60177f99298ef137ea46f18c Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Wed, 14 Oct 2015 19:35:04 +0200 Subject: [PATCH] [#4357] Fix possible assert error in GlobalEventExecutor Motivation: We started the thread before store it in a field which could lead to an assert error when the thread is executed before we actually store it. Modifications: Store thread before start it. Result: No more assert error possible. --- .../java/io/netty/util/concurrent/GlobalEventExecutor.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/io/netty/util/concurrent/GlobalEventExecutor.java b/common/src/main/java/io/netty/util/concurrent/GlobalEventExecutor.java index aade9e705f..0ab8a2509a 100644 --- a/common/src/main/java/io/netty/util/concurrent/GlobalEventExecutor.java +++ b/common/src/main/java/io/netty/util/concurrent/GlobalEventExecutor.java @@ -214,8 +214,11 @@ public final class GlobalEventExecutor extends AbstractScheduledEventExecutor { private void startThread() { if (started.compareAndSet(false, true)) { Thread t = threadFactory.newThread(taskRunner); - t.start(); + // Set the thread before starting it as otherwise inEventLoop() may return false and so produce + // an assert error. + // See https://github.com/netty/netty/issues/4357 thread = t; + t.start(); } }