real-logic / aeron

Efficient reliable UDP unicast, UDP multicast, and IPC message transport
Apache License 2.0
7.37k stars 888 forks source link

aeron-agent for cluster event generates an exception #671

Closed segabriel closed 5 years ago

segabriel commented 5 years ago

I came across a problem. I tried to repeat io.aeron.agent.LoggingAgentTest but for listening of cluster events. And I got an exception which breaks cluster:

java.lang.LinkageError: loader (instance of  sun/misc/Launcher$AppClassLoader): attempted  duplicate class definition for name: "io/aeron/cluster/Election"
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at io.aeron.cluster.ConsensusModuleAgent.onStart(ConsensusModuleAgent.java:240)
    at org.agrona.concurrent.AgentRunner.run(AgentRunner.java:154)
    at java.lang.Thread.run(Thread.java:748)

Here is my test https://gist.github.com/segabriel/649542396bc982cf2a4d3d2f710b5bbc So in my test, I enable cluster event codes and launch the agent via:

  @BeforeClass
  public static void installAgent() {
 System.setProperty(EventConfiguration.ENABLED_CLUSTER_EVENT_CODES_PROP_NAME, "all");
    System.setProperty(
        EventLogAgent.READER_CLASSNAME_PROP_NAME, StubEventLogReaderAgent.class.getName());
    EventLogAgent.agentmain("", ByteBuddyAgent.install());
  }

And then I launch a node in the single cluster mode. And I get the exception above, it happens when the leader elected.

But If I disable @BeforeClass installAgent() then everything works.

mjpt777 commented 5 years ago

There are a number of issues with this test so isolating the issue is not so simple. You don't close the services or agents so how do you know a previous one is not around?

segabriel commented 5 years ago

Yeap, but I just remove the directory which contains (media-driver, archive, consensus module, and service) before the start (clean start). https://gist.github.com/segabriel/649542396bc982cf2a4d3d2f710b5bbc#file-loggingagentclustertest-java-L62

mjpt777 commented 5 years ago

What if your rerun the test in the same JVM?

segabriel commented 5 years ago

I changed my gist with close resources. https://gist.github.com/segabriel/649542396bc982cf2a4d3d2f710b5bbc