Skip to content

fix: remove closed application contexts from the Store - #215

Open
adityaanikam wants to merge 1 commit into
wiremock:mainfrom
adityaanikam:fix-store-context-leak-214
Open

adityaanikam wants to merge 1 commit into
wiremock:mainfrom
adityaanikam:fix-store-context-leak-214

Conversation

@adityaanikam

Copy link
Copy Markdown

Fixes #214

Store keeps a map from every ApplicationContext that configured a WireMockServer to its servers, but nothing ever removes an entry. The shutdown hook registered in WireMockServerCreator stops the server when the context is closed, but the context stays in the map, so every closed test context stays reachable for the rest of the JVM along with its beans.

This adds Store.remove(ApplicationContext) and calls it from the ContextClosedEvent listener, after the server is stopped. It only removes the entry when the closed context is the one the listener was registered on. A ContextClosedEvent from a child context also reaches listeners on its parent, and that must not drop the parent's entry.

Test: StoreContextLeakTest starts a context with a WireMock server, closes it, and checks through a WeakReference that the context can be garbage collected. Without the change it fails (the context is still reachable after 50 GC attempts), and with it it passes (4 of 4 runs). The whole wiremock-spring-boot module test suite passes (80 tests) and spotlessCheck is clean (Windows, JDK 21).

Copilot AI balanced review requested due to automatic review settings October 22, 2026 17:57

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Store keeps closed ApplicationContexts alive (memory leak)

2 participants