Facing DeadlineTimeoutException when switching to Spring Boot 3.0.0 (respectfully Apache Http Client 5)

212 views Asked by At

During transition to java 17/Spring boot 3.0.0 of one of our projects some of the integration tests started failing.

For example this test :

@Test
void getMessageInfos_Success_WithNonDefaultPeriodSent() throws Exception {
    var token = createToken();
    var ciUrlMessages = format("/%s/%s/messages;directions=%s;period=%s;maxCount=2000\\?fetchText=false", CONTEXT, MAC, Direction.IN, 10);
    var ciUrlRecipients = format("/%s/%s/possible-recipients", CONTEXT, MAC);

    stub(GET, ciUrlMessages, okJson(loadJsonFromFile("/__files/inbox/inbox_standard_incomming_messages_without_text.json")));
    stub(GET, ciUrlRecipients, okJson(loadJsonFromFile("/__files/inbox/possible_recipients_only_agency.json")));

    mvc.perform(post(INBOX_MESSAGES_INFO_URL, CONTEXT, MAC)
                    .with(x509(CLIENT_CERT))
                    .header(AUTHORIZATION, BEARER + token)
                    .content(createMessageInfoRequestJsonForPeriodTests(true, 10))
                    .contentType(APPLICATION_JSON))
            .andExpect(status().isOk())
            .andExpect(jsonPath("$.[0].messageId", is("2943405")))
            .andExpect(jsonPath("$.[1].messageId", is("2899350")))
            .andExpect(jsonPath("$.[2].messageId", is("2896472")))
            .andExpect(jsonPath("$.[3].messageId", is("2855248")));

    verify(getRequestedFor(urlEqualTo(format("/%s/%s/messages;directions=%s;period=%s;maxCount=2000?fetchText=false", CONTEXT, MAC, Direction.IN, 10))));
    verify(getRequestedFor(urlEqualTo(ciUrlRecipients)));
}

I started debugging and I saw the following exception:

java.util.concurrent.ExecutionException: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:56789/VjI7MTQ4NzU4NDE1NjAxNTs2MjE7QU9TOzI1MTE5ODA7MTI1NzMwODk5Mzs9O0F-OzI1MTE5ODI7RX47MjUxMTk4MQ/kzitRN6RuUabptLwyOx2y5-dE0A/messages;directions=IN;period=10;maxCount=2000": Request execution failed
    at java.base/java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:396)
    at java.base/java.util.concurrent.CompletableFuture.get(CompletableFuture.java:2096)

which is caused by the exception:

aused by: org.apache.hc.core5.util.DeadlineTimeoutException: Deadline: 292278994-08-17T09:12:55.807+0200, 9223370335509990168 MILLISECONDS overdue
    at org.apache.hc.core5.util.DeadlineTimeoutException.from(DeadlineTimeoutException.java:49)
    at org.apache.hc.core5.pool.StrictConnPool.lease(StrictConnPool.java:217)
    at org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.lease(PoolingHttpClientConnectionManager.java:298)
    at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.acquireEndpoint(InternalExecRuntime.java:103)
    ... 46 common frames omitted

As till now we use Spring boot 2.7.x and respectfully Http client 4, we set timeouts = -1 for the

-connectionRequestTimeout
-connectTimeout
-SocketTimeout. 

And In this way no timeout was set. In Apache Http Client 5 the values for no timeout are 0, so did I. Then during the debugging, I saw, that in the lease() method of the StrictConnPool the following call is made:

acquiredLock = this.lock.tryLock(requestTimeout.getDuration(), requestTimeout.getTimeUnit());

and the returned value is false and it causes the throw of the of theDeadlineTimeoutException, which I showed before. As the

requestTimeout.getDuration()

is 0, was wondering whether this is the cause of the tryLock to return 0, because there is not actually time to get the lock? And in this case what should be the requestTimeout value, as actually I want to set no limit and actually in the HttpConfiguration I set timeout for the

-connectionRequestTimeout
-connectTimeout
-SocketTimeout

To be Timeout.DISABLED?

0

There are 0 answers