Skip to content

Commit

Permalink
Correctly handles webserver deployment failures
Browse files Browse the repository at this point in the history
  • Loading branch information
miere committed Aug 24, 2022
1 parent 6e38a7b commit 71c5f16
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions kos-core/source/kos/core/VertxWebServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,18 @@ public void start() {
public void start(Promise<Void> startFuture) {
try {
beforeStart();
tryToStartServer( startFuture );
tryToStartServer().onComplete(ar -> {
if (ar.succeeded()) startFuture.complete();
else startFuture.fail(ar.cause());
});
} catch ( Throwable cause ) {
log.error( "Could not start server", cause );
startFuture.fail(cause);
}
}

private void tryToStartServer(Promise<Void> startFuture ) {
public Future<HttpServer> tryToStartServer() {
val startFuture = Promise.<HttpServer>promise();
vertx.createHttpServer( kosContext.getHttpServerOptions() )
.requestHandler( router() )
.listen( as -> {
Expand All @@ -120,9 +124,11 @@ private void tryToStartServer(Promise<Void> startFuture ) {
val server = as.result();
Runtime.getRuntime().addShutdownHook(new Thread(server::close));
afterStart(server);
startFuture.complete();
startFuture.complete(server);
}
});

return startFuture.future();
}

private void notifyWebServerDeploymentListeners() {
Expand Down

0 comments on commit 71c5f16

Please sign in to comment.