quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.86k stars 2.71k forks source link

Async job throw error when http api already finish #44683

Open paomian opened 3 days ago

paomian commented 3 days ago

Describe the bug

I have a async task in http api method like

  @POST
  @Path("/statistics")
  @Consumes("application/json")
  @Produces("application/json")
  @WithTransaction
  public Uni<RestResponse<Map<String, String>>> greptimedbStatistic() {
        someUni.runSubscriptionOn(Infrastructure.getDefaultExecutor())
        .subscribeAsCompletionStage()
        .whenComplete(
            (ignored, throwable) -> {
              if (throwable != null) {
                LOG.error("do some thing failed.", throwable);
              }
            });
     return otherUni;
}

someUni some time throw an error: RequestScoped context was not active when trying to obtain a bean instance for a client proxy of CLASS bean [class=io.quarkus.rest.client.reactive.runtime.HeaderContainer, id=w_QyeSkhamyoJ8l04Fy3rjzMfkM]\n\t- you can activate the request context for a specific method using the @ActivateRequestContext interceptor binding"

someUni is an http request by RestClient.

@RegisterRestClient(configKey = "test")
@ClientBasicAuth(username = "${key}", password = "${val}")
interface GreptimeLogClient {

  @POST
  @Path("/v1/events/logs")
  @Consumes(MediaType.APPLICATION_JSON)
  @Produces(MediaType.APPLICATION_JSON)
  Uni<JsonObject> writeLog(
      @QueryParam("db") String db,
      @QueryParam("table") String table,
      @QueryParam("pipeline_name") String pipelineName,
      JsonObject log);
}

How to avoid this error.

Expected behavior

reqeust success

Actual behavior

throw an error

How to Reproduce?

No response

Output of uname -a or ver

Darwin my-MBP 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:14:30 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T6000 arm64

Output of java -version

openjdk version "21.0.4" 2024-07-16 OpenJDK Runtime Environment Homebrew (build 21.0.4) OpenJDK 64-Bit Server VM Homebrew (build 21.0.4, mixed mode, sharing)

Quarkus version or git rev

3.9.3

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63) Maven home: /Users/paomian/.m2/wrapper/dists/apache-maven-3.8.6-bin/67568434/apache-maven-3.8.6 Java version: 21.0.4, vendor: Homebrew, runtime: /opt/homebrew/Cellar/openjdk@21/21.0.4/libexec/openjdk.jdk/Contents/Home Default locale: en_CN, platform encoding: UTF-8 OS name: "mac os x", version: "14.6.1", arch: "aarch64", family: "mac"

Additional information

No response

geoand commented 3 days ago

Thanks for reporting.

I see you are using Quarkus 3.9. Can you try and see if you have the same problem with 3.15 and / or 3.17? If you do, please attach a sample application that we can use to see the problem in action.