Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handle RuntimeResource when an exception occurs #21121

Merged
merged 2 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void run() {
if (t instanceof PreserveTargetException) {
handleException(t.getCause(), true);
} else {
handleException(t);
handleException(t, true);
}
if (aborted) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.jboss.logging.Logger;
import org.jboss.resteasy.reactive.ResteasyReactiveClientProblem;
import org.jboss.resteasy.reactive.common.model.ResourceExceptionMapper;
import org.jboss.resteasy.reactive.server.mapping.RuntimeResource;
import org.jboss.resteasy.reactive.server.spi.ResteasyReactiveAsyncExceptionMapper;
import org.jboss.resteasy.reactive.server.spi.ResteasyReactiveExceptionMapper;
import org.jboss.resteasy.reactive.spi.BeanFactory;
Expand Down Expand Up @@ -99,31 +100,46 @@ public void mapException(Throwable throwable, ResteasyReactiveRequestContext con

private void logBlockingErrorIfRequired(Throwable throwable, ResteasyReactiveRequestContext context) {
if (isBlockingProblem(throwable)) {
log.error("A blocking operation occurred on the IO thread. This likely means you need to annotate "
+ context.getTarget().getResourceClass().getName() + "#" + context.getTarget().getJavaMethodName() + "("
+ Arrays.stream(context.getTarget().getParameterTypes()).map(Objects::toString)
.collect(Collectors.joining(", "))
+ ") with @"
+ Blocking.class.getName()
+ ". Alternatively you can annotate the class " + context.getTarget().getResourceClass().getName()
+ " to make every method on the class blocking, or annotate your sub class of the "
+ Application.class.getName() + " class to make the whole application blocking");
RuntimeResource runtimeResource = context.getTarget();
if (runtimeResource == null) {
log.error("A blocking operation occurred on the IO thread. This likely means you need to use the @"
+ Blocking.class.getName() + " annotation on the Resource method, class or "
+ Application.class.getName() + " class.");
} else {
log.error("A blocking operation occurred on the IO thread. This likely means you need to annotate "
+ runtimeResource.getResourceClass().getName() + "#" + runtimeResource.getJavaMethodName() + "("
+ Arrays.stream(runtimeResource.getParameterTypes()).map(Objects::toString)
.collect(Collectors.joining(", "))
+ ") with @"
+ Blocking.class.getName()
+ ". Alternatively you can annotate the class " + runtimeResource.getResourceClass().getName()
+ " to make every method on the class blocking, or annotate your sub class of the "
+ Application.class.getName() + " class to make the whole application blocking");
}
}
}

private void logNonBlockingErrorIfRequired(Throwable throwable, ResteasyReactiveRequestContext context) {
if (isNonBlockingProblem(throwable)) {
log.error(
"An operation that needed be run on a Vert.x EventLoop thread was run on a worker pool thread. This likely means you need to annotate "
+ context.getTarget().getResourceClass().getName() + "#" + context.getTarget().getJavaMethodName()
+ "("
+ Arrays.stream(context.getTarget().getParameterTypes()).map(Objects::toString)
.collect(Collectors.joining(", "))
+ ") with @"
+ NonBlocking.class.getName()
+ ". Alternatively you can annotate the class " + context.getTarget().getResourceClass().getName()
+ " to make every method on the class run on a Vert.x EventLoop thread, or annotate your sub class of the "
+ Application.class.getName() + " class to affect the entire application");
RuntimeResource runtimeResource = context.getTarget();
if (runtimeResource == null) {
log.error(
"An operation that needed be run on a Vert.x EventLoop thread was run on a worker pool thread. This likely means you use the @"
+ NonBlocking.class.getName() + " annotation on the Resource method, class or "
+ Application.class.getName() + " class.");
} else {
log.error(
"An operation that needed be run on a Vert.x EventLoop thread was run on a worker pool thread. This likely means you need to annotate "
+ runtimeResource.getResourceClass().getName() + "#" + runtimeResource.getJavaMethodName()
+ "("
+ Arrays.stream(runtimeResource.getParameterTypes()).map(Objects::toString)
.collect(Collectors.joining(", "))
+ ") with @"
+ NonBlocking.class.getName()
+ ". Alternatively you can annotate the class " + runtimeResource.getResourceClass().getName()
+ " to make every method on the class run on a Vert.x EventLoop thread, or annotate your sub class of the "
+ Application.class.getName() + " class to affect the entire application");
}
}
}

Expand Down