setPeriodic() does not stop if the start of a verticle fails

238 views
Skip to first unread message

Philipp Lehninger

unread,
Sep 1, 2017, 11:30:51 AM9/1/17
to vert.x
Hi,
I am a little bit confused about this behaviour:
If a Verticle fails at startup, Vertx does not stop the Verticle's tasks.
As it has not been successfully deployed, I cannot undeploy the Verticle.

Is this behavior intended?
If so, how can I avoid it?

Best regards,
Philipp

CODE
==================

public class VertxStarter {

private static Logger logger;

    public static void main(String[] args) throws InterruptedException {
logger = LoggerFactory.getLogger(VertxStarter.class);
        Vertx vertx = Vertx.vertx();

        vertx.deployVerticle(new Vertxtest(), event -> {
if (event.succeeded()) {
logger.info("deployment succeeded");
}
else {
logger.info("deployment failed");
vertx.setTimer(15000, timer -> {
StringBuilder strb = new StringBuilder("IDs of all deployed modules: ");
vertx.deploymentIDs().forEach(id -> {
strb.append(id);
strb.append(" ");
});
logger.info(strb.toString());
});
}
});
    }
}

public class Vertxtest extends AbstractVerticle{

private Logger logger;
    @Override
    public void start(Future<Void> future) {

logger = LoggerFactory.getLogger(Vertxtest.class);
logger.info("verticle started");
        
vertx.setPeriodic(6000, timer -> logger.info("still alive"));
future.fail("wanted a fail for testing");
    }
@Override
public void stop(){
logger.info("verticle stopped");
}
}

==================

The gradle project is attached.
vertxtest.zip

Blake

unread,
Sep 3, 2017, 9:41:59 PM9/3/17
to vert.x
Hey Philip,

In this case you're running embedded and the vert.x instance does not stop even though a verticle failed to deploy. 
If this was started by the Vert.x Launcher and you failed on the main verticle being deployed, the program would simply stop.

I don't believe this is intended behavior, as periodic timers are supposed to be registered on the context which they were deployed and if that context dies the shutdown hook should remove them, but the shutdown hook is not called for the context when the verticle fails to deploy.

This question probably needs to go up to vertx-dev to see how they want to handle these situations. This also happens when running via Launcher and a verticle fails to deploy (e.g., You are deploying multiple verticles from a starter verticle, but don't want to fail the main verticle even if one -- let's say a noncritical -- verticle fails to deploy).

I'll go ahead and post this to vertx-dev and you can follow up there to see what they say. https://groups.google.com/forum/#!topic/vertx-dev/rS5jKhhxuX4

Philipp Lehninger

unread,
Sep 4, 2017, 2:58:46 AM9/4/17
to vert.x
Hi Blake,

Thank you for your reply, I will follow the discussion you opened on vertx-dev.
I think you described my problem much better.

e.g., You are deploying multiple verticles from a starter verticle, but don't want to fail the main verticle even if one -- let's say a noncritical -- verticle fails to deploy

This is exactly, what I want to achieve.
As I stumbled upon this behavior, I wrote the attached test verticle.

Best regards :)


Am Montag, 4. September 2017 03:41:59 UTC+2 schrieb Blake:
Reply all
Reply to author
Forward
0 new messages