Fix memory leak in NameResolverGroup

Motivation:

NameResolverGroup uses the EventExecutor specified with getResolver() as
the key of its internal map.  Because the EventExecutor is often a
wrapped one, such as PausibleChannelEventExecutor, which actually is a
wrapper of the same executor, they should instantiate only one
NameResolver.

Modifications:

Unwrap the EventExecutor before using it as the key of the internal map

Result:

Memory leak is gone.
This commit is contained in:
Trustin Lee 2014-11-20 20:22:17 +09:00
parent 5f8483646b
commit d7f5353fe8

View File

@ -49,7 +49,7 @@ public abstract class NameResolverGroup<T extends SocketAddress> implements Clos
* {@link #newResolver(EventExecutor)} so that the new resolver is reused on another
* {@link #getResolver(EventExecutor)} call with the same {@link EventExecutor}.
*/
public NameResolver<T> getResolver(final EventExecutor executor) {
public NameResolver<T> getResolver(EventExecutor executor) {
if (executor == null) {
throw new NullPointerException("executor");
}
@ -58,6 +58,10 @@ public abstract class NameResolverGroup<T extends SocketAddress> implements Clos
throw new IllegalStateException("executor not accepting a task");
}
return getResolver0(executor.unwrap());
}
private NameResolver<T> getResolver0(final EventExecutor executor) {
NameResolver<T> r;
synchronized (resolvers) {
r = resolvers.get(executor);