citrusframework / citrus

Framework for automated integration tests with focus on messaging integration
https://citrusframework.org
Apache License 2.0
445 stars 135 forks source link

NullPointerException. Cannot invoke "org.apache.hc.client5.http.io.ManagedHttpClientConnection.isConsistent()" because "conn" is null #1139

Closed akuz0 closed 2 months ago

akuz0 commented 3 months ago

Citrus Version 4.1.0

I tried to solve a problem from a task #1137 and for parallel run i have flaky error.

Config junit

junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent

I`m not shure, but we use 5.3</httpclient.version> but this problem fixed for [5.3.1]

check issue https://issues.apache.org/jira/browse/HTTPCLIENT-2313

Actual behavior


org.citrusframework.exceptions.TestCaseFailedException: java.lang.NullPointerException: Cannot invoke "org.apache.hc.client5.http.io.ManagedHttpClientConnection.isConsistent()" because "conn" is null

    at org.citrusframework.DefaultTestCase.executeFinalActions(DefaultTestCase.java:224)
    at org.citrusframework.DefaultTestCase.finish(DefaultTestCase.java:177)
    at org.citrusframework.DefaultTestCaseRunner.stop(DefaultTestCaseRunner.java:52)
    at org.citrusframework.common.DefaultTestLoader.load(DefaultTestLoader.java:107)
    at org.citrusframework.junit.jupiter.CitrusExtension.interceptTestMethod(CitrusExtension.java:156)
    at org.citrusframework.junit.jupiter.spring.CitrusSpringExtension.interceptTestMethod(CitrusSpringExtension.java:87)
    at java.base/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:194)
    at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
    at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
    at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
    at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
    at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
Caused by: org.citrusframework.exceptions.CitrusRuntimeException: java.lang.NullPointerException: Cannot invoke "org.apache.hc.client5.http.io.ManagedHttpClientConnection.isConsistent()" because "conn" is null
    at org.citrusframework.actions.SendMessageAction.lambda$doExecute$1(SendMessageAction.java:166)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.NullPointerException: Cannot invoke "org.apache.hc.client5.http.io.ManagedHttpClientConnection.isConsistent()" because "conn" is null
    at org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.release(PoolingHttpClientConnectionManager.java:412)
    at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.discardEndpoint(InternalExecRuntime.java:246)
    at org.apache.hc.client5.http.impl.classic.InternalExecRuntime.releaseEndpoint(InternalExecRuntime.java:260)
    at org.apache.hc.client5.http.impl.classic.ResponseEntityProxy.releaseConnection(ResponseEntityProxy.java:80)
    at org.apache.hc.client5.http.impl.classic.ResponseEntityProxy.eofDetected(ResponseEntityProxy.java:115)
    at org.apache.hc.core5.http.io.EofSensorInputStream.checkEOF(EofSensorInputStream.java:199)
    at org.apache.hc.core5.http.io.EofSensorInputStream.read(EofSensorInputStream.java:136)
    at java.base/java.io.InputStream.readNBytes(InputStream.java:409)
    at java.base/java.io.InputStream.readAllBytes(InputStream.java:346)
    at org.citrusframework.util.FileUtils.copyToByteArray(FileUtils.java:424)
    at org.citrusframework.http.interceptor.LoggingClientInterceptor$CachingClientHttpResponseWrapper.getBody(LoggingClientInterceptor.java:220)
    at org.citrusframework.http.interceptor.LoggingClientInterceptor$CachingClientHttpResponseWrapper.getBodyContent(LoggingClientInterceptor.java:227)
    at org.citrusframework.http.interceptor.LoggingClientInterceptor.getResponseContent(LoggingClientInterceptor.java:159)
    at org.citrusframework.http.interceptor.LoggingClientInterceptor.intercept(LoggingClientInterceptor.java:70)
    at org.springframework.http.client.InterceptingClientHttpRequest$InterceptingRequestExecution.execute(InterceptingClientHttpRequest.java:87)
    at org.springframework.http.client.InterceptingClientHttpRequest.executeInternal(InterceptingClientHttpRequest.java:71)
    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:879)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:821)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:682)
    at org.citrusframework.http.client.HttpClient.send(HttpClient.java:132)
    at org.citrusframework.actions.SendMessageAction.lambda$doExecute$1(SendMessageAction.java:161)
    ... 3 more

Test case sample

Please, share the test case (as small as possible) which shows the issue

akuz0 commented 3 months ago

I will try to analyze the issue, but it can be challenging to grasp.

Why am I so sure that the problem has something to do with parallel startup? This error occurred for the first time when I ran the program in parallel, and it didn't happen if I disabled parallel execution. It's possible that it was just a coincidence, but it seems more likely that there's some underlying issue with parallel execution that needs to be addressed.

christophd commented 3 months ago

In case you know that this is fixed with httpclient version 5.3.1 you can explicitly add this version as a Maven dependency to your project (maybe in scope test). This should then use the newer version to run the tests.

We will also update the versions with the next Citrus release version then.

akuz0 commented 3 months ago

@christophd I'll try my best, but the error occurs in only 1 out of 50 instances, and it can be difficult to identify.