micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.02k stars 1.05k forks source link

Block detection for methods annotated with `@Blocking` #10020

Open sdelamo opened 10 months ago

sdelamo commented 10 months ago

We have an annotation @Blocking

  • A marker annotation for methods that are blocking.

@yawkat added a really useful PR to detect blocking usages of @BlockingClient in a Netty event loop thread.

BlockingHttpClient is annotated with @Blocking.

Micronaut Data's CrudRepository repository is annotated with @Blocking as well. We have other instances throughout the framework.

We could enhance the @yawkat block detector to detect when an application executes a method annotated with @Blocking in a Netty event loop thread and, in that case, throw an exception.

@micronaut-projects/core-developers thoughts?

timyates commented 5 months ago

🤔 So, we could do this by making @Blocking into an Around annotation with a Type to handle the wrapping.

@Blocking is in micronaut-core, @Type is in micronaut-inject and @Around is in micronaut-aop so we would need to move things around (which I believe would mean this is delayed until micronaut 5.0.0 due to it being a blocking change?)

Unless there's a programatic way of wrapping each Blocking method or class in.a check for the Netty event-loop threads...