Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertionError on shutdown #5

Open
recunius opened this issue Feb 3, 2015 · 0 comments
Open

AssertionError on shutdown #5

recunius opened this issue Feb 3, 2015 · 0 comments

Comments

@recunius
Copy link

recunius commented Feb 3, 2015

When assertions are enabled (-ea flag) shutting down Gearman is throwing an exception. If assertions are disabled the server appears to shutdown and the java process terminates successfully.

Here is a fairly simple test case:

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.gearman.Gearman;
import org.gearman.GearmanClient;
import org.gearman.GearmanFunction;
import org.gearman.GearmanFunctionCallback;
import org.gearman.GearmanJobEvent;
import org.gearman.GearmanJobEventCallback;
import org.gearman.GearmanJoin;
import org.gearman.GearmanServer;
import org.gearman.GearmanWorker;

public class GearmanLifecycleCli {

  public void run() throws Exception {
    Gearman gearman = Gearman.createGearman();
    GearmanWorker worker = gearman.createGearmanWorker();
    GearmanClient client = gearman.createGearmanClient();
    GearmanServer server = gearman.createGearmanServer("localhost", 4730);
    client.addServer(server);

    worker.addServer(server);
    worker.addFunction("echo", new EchoFunction());

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    GearmanJoin<String> join = client.submitJob("echo", "Hello Gearman Worker".getBytes(), "ATTACHMENT", new GearmanJobEventCallback<String>() {

      @Override
      public void onEvent(String attachment, GearmanJobEvent event) {
        switch (event.getEventType()) {
        case GEARMAN_JOB_DATA:
        case GEARMAN_JOB_SUCCESS: {
          byte[] results = event.getData();
          try {
            bos.write(results);
          } catch (IOException e) {
            e.printStackTrace();
          }
          break;
        }
        }

      }

    });
    join.join();

    String result = new String(bos.toByteArray(), "UTF-8");
    System.out.println("Result: " + result);
    gearman.shutdown();

  }

  public static class EchoFunction implements GearmanFunction {

    @Override
    public byte[] work(String function, byte[] data, GearmanFunctionCallback callback) throws Exception {
      return data;
    }

  }

  public static void main(String[] argv) {
    GearmanLifecycleCli cli = new GearmanLifecycleCli();
    try {
      cli.run();
    } catch (Exception e) {
      System.out.println(e);
      e.printStackTrace();
    }
  }
}

Here is the program output with stack trace when assertions are on:

Result: Hello Gearman Worker Exception in thread "main" java.lang.AssertionError at org.gearman.impl.client.ClientImpl.dropController(ClientImpl.java:256) at org.gearman.impl.client.ClientImpl.access$600(ClientImpl.java:56) at org.gearman.impl.client.ClientImpl$InnerConnectionController.onDrop(ClientImpl.java:130) at org.gearman.impl.serverpool.AbstractConnectionController.dropServer(AbstractConnectionController.java:474) at org.gearman.impl.serverpool.AbstractConnectionController.dropServer(AbstractConnectionController.java:444) at org.gearman.impl.serverpool.AbstractJobServerPool.removeServer(AbstractJobServerPool.java:153) at org.gearman.impl.serverpool.AbstractJobServerPool.removeAllServers(AbstractJobServerPool.java:135) at org.gearman.impl.serverpool.AbstractJobServerPool.shutdown(AbstractJobServerPool.java:229) at org.gearman.impl.client.ClientImpl.shutdown(ClientImpl.java:406) at org.gearman.impl.GearmanImpl.shutdown(GearmanImpl.java:96) at vericle.cli.experiments.GearmanLifecycleCli.run(GearmanLifecycleCli.java:53) at vericle.cli.experiments.GearmanLifecycleCli.main(GearmanLifecycleCli.java:69)

Has anyone run into this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant