Open 1534196496 opened 7 months ago
I was dealing with the same issue two weeks ago so I could provide more details. The problem occurs only when adding expectation of type ExpectationResponseCallback
that leads to registration of WebSocketClient
required for reading the request so it can be used for generating response. WebSocketClient
is subscribed to MockServerEventBus
to listen for STOP
and RESET
events. There is a single MockServerEventBus
for each port stored in static final field EVENT_BUS_MAP
within class MockServerClient
. When calling org.mockserver.client.MockServerClient#reset
, RESET
event is propagated to each subscriber but the issue is that subscribers registered within MockServerEventBus
are never cleared, therefore, WebSocketClient
s don't become eligible for garbage collection during the tests run.
In my case I was able to bypass the issue by using the method clear to clear logs and manually remove expectations by ids to avoid calling the reset method. Using org.mockserver.client.ForwardChainExpectation#respond(org.mockserver.mock.action.ExpectationResponseCallback)
is necessary only for expectations that need the ability to read the request and by registering them only once it one can mitigate the problem.
On the other hand, this state is far from ideal and subscribers in MockServerEventBus
could be cleared once the event was propagated to them.
Describe the issue A memory leak caused by the reset method not removing subscribers ultimately leads to an OutOfMemoryError
What you are trying to do Periodic reloading of Expectations.
MockServer version 5.15.0 To Reproduce ClientAndServer client = ClientAndServer.startClientAndServer(92); while (true) { client.when( request().withPath("/aaaa") ).withId("888") .respond( r -> response().withBody("1234") ); client.reset(); }
How you are running MockServer (i.e maven plugin, docker, etc) java Client
Code you used to create expectations ClientAndServer client = ClientAndServer.startClientAndServer(92); client .when(....) .respond(....)
What error you saw oom