Skip to content

Commit

Permalink
Merge pull request #21121 from geoand/#21120
Browse files Browse the repository at this point in the history
Better handle RuntimeResource when an exception occurs
  • Loading branch information
stuartwdouglas authored Nov 1, 2021
2 parents 9300301 + 6cd9b08 commit 6ce54c4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 21 deletions.
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

0 comments on commit 6ce54c4

Please sign in to comment.