Skip to content

Commit

Permalink
fix: worker-poll tasks shouldn't block main loop (#7427)
Browse files Browse the repository at this point in the history
Fixes a call to execute a task on the worker pool that still may block main event-loop
execution. See #7358 for more information.

Reviewers: @guozhangwang
  • Loading branch information
vvcephei authored Apr 23, 2021
1 parent 69b51c7 commit 0b0bf65
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public void authenticate(

server.getWorkerExecutor().executeBlocking(
p -> getUser(contextName, username, password, allowedRoles, p),
false,
resultHandler
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void handle(final RoutingContext routingContext) {

workerExecutor.<Void>executeBlocking(
promise -> authorize(promise, routingContext),
false,
ar -> handleAuthorizeResult(ar, routingContext));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -253,11 +254,11 @@ private void handleAsyncExecution() {
when(server.getWorkerExecutor()).thenReturn(worker);
doAnswer(invocation -> {
final Handler<Promise<User>> blockingCodeHandler = invocation.getArgument(0);
final Handler<AsyncResult<User>> resultHandler = invocation.getArgument(1);
final Handler<AsyncResult<User>> resultHandler = invocation.getArgument(2);
final Promise<User> promise = Promise.promise();
promise.future().onComplete(resultHandler);
blockingCodeHandler.handle(promise);
return null;
}).when(worker).executeBlocking(any(), any());
}).when(worker).executeBlocking(any(), eq(false), any());
}
}

0 comments on commit 0b0bf65

Please sign in to comment.