Race Condition Using Future.compose()?

54 views
Skip to first unread message

deven.p...@redhat.com

unread,
Jan 21, 2018, 3:56:56 PM1/21/18
to vert.x
I have a block of code like:

public void start(Future<Void> startFuture) {
// ConfigStore from Kube/OCPs
Future<JsonObject> f1 = Future.future();
this.initConfigRetriever(f1.completer())
.compose(this::asyncLoadDbSchema)
.compose(this::provisionRouter)
.compose(this::createHttpServer, startFuture);
}

As best I can tell using logging statements, during the "provisionRouter" method, I get an IllegalStateException complaining that the Future is already completed. I've been banging my head on it for the whole day today and I am not making much progress.

The code inside of the "provisionRouter" method looks like: 

Future<OpenAPI3RouterFactory> provisionRouter(Void v) {
System.out.println("Router provisioning");
service = AdjectiveService.createProxy(vertx, "adjective.service");
Future<OpenAPI3RouterFactory> future = Future.future();
createRouterFactoryFromFile(vertx, "adjective.yml", future.completer());
return future;
}

My best guess is that the future becomes completed so quickly that the compose sees it as already complete?

Anyhow, whatever help received would be greatly appreciated!

Deven

deven.p...@redhat.com

unread,
Jan 21, 2018, 4:30:47 PM1/21/18
to vert.x
I have tried this configuration as well (which seems to match the examples more closely):

public void start(Future<Void> startFuture) {
// ConfigStore from Kube/OCPs
Future<JsonObject> f1 = Future.future();
this.initConfigRetriever(f1.completer())
.compose(this::asyncLoadDbSchema)
.compose(this::provisionRouter)
            .compose(f -> createHttpServer(startFuture, f), startFuture);
}

And the createHttpServerMethod looks like

void createHttpServer(Future startFuture, OpenAPI3RouterFactory factory) {
System.out.println("Adding API handles");
factory.addHandlerByOperationId("getAdjective", this::handleAdjGet);
factory.addHandlerByOperationId("saveAdjective", this::handleAdjPost);
factory.addHandlerByOperationId("health", this::healthCheck);
System.out.println("Creating HTTP Server");
JsonObject httpJsonCfg = vertx
.getOrCreateContext()
.config()
.getJsonObject("http");
HttpServerOptions httpConfig = new HttpServerOptions(httpJsonCfg);
vertx.createHttpServer(httpConfig)
.requestHandler(factory.getRouter()::accept)
.listen(startFuture.completer());
}

But I am still getting the exact same error indications.

Thanks in advance!

Deven

deven.p...@redhat.com

unread,
Jan 21, 2018, 4:33:52 PM1/21/18
to vert.x
If you would like to see the whole codebase, have a look at: https://github.com/rhoar-shootout/rhoar-vertx

Deven

deven.p...@redhat.com

unread,
Jan 21, 2018, 5:20:06 PM1/21/18
to vert.x
I did some more experimentation and as far as I can tell what I am doing SHOULD work.. This example DOES work:

public void start(Future<Void> startFuture) {
    vertx.eventBus().consumer("msg.ping").handler(msg -> {
msg.reply(String.format("Pong: %d", Instant.now().getEpochSecond()));
});

Future<Message<String>> f1 = Future.future();
vertx.eventBus().send("msg.ping", null, f1.completer());
f1.compose(this::pingHandler)
.compose(this::pingHandler)
.compose(this::pingHandler)
.compose(this::pingHandler)
.compose(this::pingHandler)
.compose(this::pingHandler)
.compose(m -> {
pingHandler(m).setHandler(res -> {
if (res.succeeded()) {
startFuture.complete();
} else {
startFuture.fail(res.cause());
}
});
}, startFuture);
}

Any thoughts? Anyone?

Thanks in advance!

Deven

deven.p...@redhat.com

unread,
Jan 21, 2018, 6:02:10 PM1/21/18
to vert.x
I made a LITTLE progress. I had the syntax for the `compose()` incorrect and have now resolved it but I am still getting hung when trying to retrieve the config. I will start a new thread to address that concern.

Cheers,

Deven 

Clement Escoffier

unread,
Jan 22, 2018, 4:25:50 AM1/22/18
to ve...@googlegroups.com
Hello Deven,

How do you retrieve the configuration?

Clement

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/675fb1ec-09a1-46e2-b264-470f81a7e6ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Deven Phillips

unread,
Jan 22, 2018, 2:53:22 PM1/22/18
to vert.x
Clement,

    I'm using a combination of JSON file and Kubernetes ConfigMap (If the KUBERENETS_NAMESPACE environment variable is present)... I figured that problem out though. On to newer and more annoying issues!

For anyone curious, the code is at: https://github.com/rhoar-shootout/rhoar-vertx

Deven

Clement Escoffier

unread,
Jan 22, 2018, 3:04:34 PM1/22/18
to ve...@googlegroups.com
In 3.5.1, we have improved optional config store and avoid failing when retrieving a config map outside of Kubernetes.

Clement

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
Reply all
Reply to author
Forward
0 new messages