Skip to content

Netty instrumentation causes memory leak and more #2705

@raptium

Description

@raptium

Describe the bug
io.netty.channel.ChannelFuture#addListener() is transformed to wrap the input listener with a helper class.
However the removeListener() removeListeners() counterparts are never transformed. Once a listener is added to the future, it can never be removed. This may cause memory leak and even logical incorrectness.

Steps to reproduce

import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;

public class NettyChannelFutureDemo {
    public static void main(String[] args) {
        EmbeddedChannel channel = new EmbeddedChannel();
        for (int i = 0; i < 100; i++) {
            GenericFutureListener<Future<Object>> listener = future -> {
                System.out.println("channel closed");
            };
            channel.closeFuture().addListener(listener);
            channel.closeFuture().removeListener(listener); // not removed if netty instrumentation is on
        }
        try {
            channel.close().await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

What did you expect to see?
channel closed should never be printed since listeners are removed before the future completes.

What did you see instead?
channel closed is printed 100 times.

What version are you using?
v1.0.1

Environment
Compiler: AdoptOpenJDK 11.0.10
OS: Microsoft Windows 10

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions