spring-cloud-contract icon indicating copy to clipboard operation
spring-cloud-contract copied to clipboard

Wiremock server becomes unresponsive when ContextCache is evicted by removeEldestEntry()

Open rszabolcs opened this issue 2 years ago • 4 comments

Remarks

Initially I raised this issue here and here. Then I was suggested to report it here instead.

Description

We have a project in Spring Boot (version 2.7.14) that is extensively tested and we noticed that at some point some of our tests start failing without apparent reason.

I could boil down the issue into a sample project as seen here. Run the whole test suite and the last service test will fail but it shouldn't.

After digging into the details you can find that after DefaultContextCache.this.remove(eldest.getKey(), HierarchyMode.CURRENT_LEVEL) is called within removeEldestEntry() in LruCache then something happens that makes Wiremock server to behave instable.

If we replace this logic to not remove an element but to reset the whole cache then all tests will be green. This workaround is found here.

Reproduction steps

Run the whole test suite here and the last service test will fail but it shouldn't.

rszabolcs avatar Sep 18 '23 06:09 rszabolcs

Are you willing to file a PR to Spring Cloud Contract (3.1.x I guess) with a failing text and a fix (I see that you have a workaround)?

marcingrzejszczak avatar Sep 18 '23 14:09 marcingrzejszczak

Hello, thanks for checking it! I'm not sure this workaround of mine would be a proper solution. I don't fully understand why the workaround works exactly. Somehow WireMock gets screwed when ContextCache is evicted to make it possible to add an element again. When we reset it instead of removing an element, apparently it's working fine. But I wouldn't know why.

rszabolcs avatar Sep 20 '23 11:09 rszabolcs

Ok, so are you able to create a test that will break with the current implementation?

marcingrzejszczak avatar Sep 25 '23 09:09 marcingrzejszczak

Exactly. Run the whole test suite of main branch of this repo. The last service test will fail but it shouldn't.

rszabolcs avatar Sep 25 '23 10:09 rszabolcs