Skip to content

Commit

Permalink
Remove switching executor for onReady/onCancel/onComplete.
Browse files Browse the repository at this point in the history
This fixes the issue with the interleaving of onReady and onMessageAndHalfClose with the Vert.x SDK. Without this commit, both onReady and onMessageAndHalfClose will set and unset the gRPC Context. Doing so mutates the Vert.x Context, which is unique per Executor and shared among executor tasks. Because the userExecutor is Vertx.executeBlocking with ordered = false, Vert.x executes the tasks in parallel, so it is possible that the execution of onMessageAndHalfClose interleaves with the ending of onReady, which detaches the context, thus causing a syscall not found issue.
  • Loading branch information
slinkydeveloper committed Jun 30, 2023
1 parent c45e29d commit 0e62582
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,30 @@ public void onMessageAndHalfClose(MessageLite message) {
userExecutor.execute(() -> listener.onMessageAndHalfClose(message));
}

// A bit of explanation why the following methods are not executed on the user executor.
//
// The listener methods onReady/onCancel/onComplete are used purely for notification reasons,
// they don't execute any user code.
//
// Running them in the userExecutor can also be problematic if the listener
// mutates some thread local and runs tasks in parallel.
// This is the case when using Vertx.executeBlocking with ordered = false and mutating the
// Vert.x Context, which is shared among every task running in the executeBlocking thread pool
// as thread local.

@Override
public void onCancel() {
userExecutor.execute(listener::onCancel);
listener.onCancel();
}

@Override
public void onComplete() {
userExecutor.execute(listener::onComplete);
listener.onComplete();
}

@Override
public void onReady() {
userExecutor.execute(listener::onReady);
listener.onReady();
}
}

Expand Down

0 comments on commit 0e62582

Please sign in to comment.