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

MP Fault tolerance @Timeout doesn't work with MP Rest Client #1783

Closed
rafabene opened this issue May 13, 2020 · 3 comments · Fixed by #1843
Closed

MP Fault tolerance @Timeout doesn't work with MP Rest Client #1783

rafabene opened this issue May 13, 2020 · 3 comments · Fixed by #1843
Assignees
Labels
1.x Issues for 1.x version branch fault-tolerance MP rest-client
Milestone

Comments

@rafabene
Copy link

Environment Details

  • Helidon Version: 1.4.4
  • Helidon MP
  • JDK version: 14
  • OS: MacOS

Problem Description

When a method using the @timeout(500) annotation invokes a long duration remote service using MP RestClient, the TimeoutException occurs after 2 seconds.

The expected TimeoutException should occur after 500ms. This is due to https://github.com/oracle/helidon/blob/master/microprofile/fault-tolerance/src/main/java/io/helidon/microprofile/faulttolerance/CommandRetrier.java class that uses a default retryValue of 2 retries attempts with 1 second each. The @timeout annotation is not being considered here.

Steps to reproduce

Create a service A with the following code that access a service B (running at http://localhost:8081/test) That takes 10 seconds to reply (You can use Thread.sleep).

Service A:

@Timeout(500)
@GET
public String checkTimeout() throws IllegalStateException, RestClientDefinitionException, MalformedURLException {
        RestClientBuilder
            .newBuilder()
            .baseUrl(new URL("http://localhost:8081/"))
            .build(RemoteService.class)
            .test();
    return "Never from normal processing";
}

@Path("/test")
@RegisterRestClient
interface RemoteService {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String test();

}

Service B

   public Response doGet() throws InterruptedException {
		Thread.sleep(1000 * 1000);
		return Response.ok("OK").build();
  } 
@tomas-langer tomas-langer added 1.x Issues for 1.x version branch fault-tolerance MP rest-client labels May 13, 2020
@spericas
Copy link
Member

As explained here,

https://download.eclipse.org/microprofile/microprofile-fault-tolerance-1.1.2/microprofile-fault-tolerance-spec.html#timeout

if used without @Asynchronous there are some cases in which a thread cannot be interrupted. I will investigate if this is related to the CommandRetrier, but regardless that's something to keep in mind.

@spericas spericas added this to the 2.0.0 milestone May 14, 2020
@spericas spericas self-assigned this May 15, 2020
@spericas
Copy link
Member

@rafabene As a workaround, try adjusting the read timeout on the builder as follows:

RestClientBuilder.newBuilder()
    .readTimeout(500, TimeUnit.MILLISECONDS)
    ...

@rafabene
Copy link
Author

Yeap. That was what I did, but my point was to demonstrate the usage of @timeout in MP-FT

Thanks

@rafabene As a workaround, try adjusting the read timeout on the builder as follows:

RestClientBuilder.newBuilder()
    .readTimeout(500, TimeUnit.MILLISECONDS)
    ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x Issues for 1.x version branch fault-tolerance MP rest-client
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants