Skip to content

Commit

Permalink
Context#executeBlocking does not log blocked threads - fixes #1633
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Sep 21, 2016
1 parent 9736108 commit e4eb213
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/main/java/io/vertx/core/impl/ContextImpl.java
Expand Up @@ -248,10 +248,14 @@ <T> void executeBlocking(Action<T> action, Handler<Future<T>> blockingCodeHandle
Object queueMetric = metrics != null ? metrics.submitted() : null; Object queueMetric = metrics != null ? metrics.submitted() : null;
try { try {
exec.execute(() -> { exec.execute(() -> {
VertxThread current = (VertxThread) Thread.currentThread();
Object execMetric = null; Object execMetric = null;
if (metrics != null) { if (metrics != null) {
execMetric = metrics.begin(queueMetric); execMetric = metrics.begin(queueMetric);
} }
if (!DISABLE_TIMINGS) {
current.executeStart();
}
Future<T> res = Future.future(); Future<T> res = Future.future();
try { try {
if (blockingCodeHandler != null) { if (blockingCodeHandler != null) {
Expand All @@ -263,6 +267,10 @@ <T> void executeBlocking(Action<T> action, Handler<Future<T>> blockingCodeHandle
} }
} catch (Throwable e) { } catch (Throwable e) {
res.fail(e); res.fail(e);
} finally {
if (!DISABLE_TIMINGS) {
current.executeEnd();
}
} }
if (metrics != null) { if (metrics != null) {
metrics.end(execMetric, res.succeeded()); metrics.end(execMetric, res.succeeded());
Expand Down
30 changes: 27 additions & 3 deletions src/test/java/io/vertx/test/core/BlockedThreadCheckerTest.java
Expand Up @@ -61,9 +61,33 @@ public void start() throws InterruptedException {
vertxOptions.setMaxWorkerExecuteTime(1000000000); vertxOptions.setMaxWorkerExecuteTime(1000000000);
vertxOptions.setWarningExceptionTime(1000000000); vertxOptions.setWarningExceptionTime(1000000000);
Vertx newVertx = vertx(vertxOptions); Vertx newVertx = vertx(vertxOptions);
DeploymentOptions depolymentOptions = new DeploymentOptions(); DeploymentOptions deploymentOptions = new DeploymentOptions();
depolymentOptions.setWorker(true); deploymentOptions.setWorker(true);
newVertx.deployVerticle(verticle, depolymentOptions); newVertx.deployVerticle(verticle, deploymentOptions);
await();
}

@Test
public void testBlockCheckExecuteBlocking() throws Exception {
Verticle verticle = new AbstractVerticle() {
@Override
public void start() throws InterruptedException {
vertx.executeBlocking(fut -> {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
fail();
}
testComplete();
}, ar -> {});
}
};
// set warning threshold to 1s and the exception threshold as well
VertxOptions vertxOptions = new VertxOptions();
vertxOptions.setMaxWorkerExecuteTime(1000000000);
vertxOptions.setWarningExceptionTime(1000000000);
Vertx newVertx = vertx(vertxOptions);
newVertx.deployVerticle(verticle);
await(); await();
} }
} }

0 comments on commit e4eb213

Please sign in to comment.