Skip to content

Fix/214 release closed contexts - #216

Open
rocky-bgta wants to merge 3 commits into
wiremock:mainfrom
rocky-bgta:fix/214-release-closed-contexts
Open

rocky-bgta wants to merge 3 commits into
wiremock:mainfrom
rocky-bgta:fix/214-release-closed-contexts

Conversation

@rocky-bgta

@rocky-bgta rocky-bgta commented Oct 31, 2026 •

Copy link
Copy Markdown

Summary

Fixes #214.

This PR addresses a memory leak in the WireMock Spring Boot integration where closed Spring ApplicationContexts remain referenced by the internal Store.

Root Cause

The Store maintains a ConcurrentHashMap with ApplicationContext instances as keys.

When an ApplicationContext is closed, WireMockServerCreator stops the associated WireMock server but does not remove the context from Store.

As a result, closed ApplicationContexts remain strongly referenced and cannot be garbage collected.

Changes

  • Added a remove() method to Store to clean up context entries.
  • Updated WireMockServerCreator to remove the context when ContextClosedEvent occurs.
  • Used a finally block to ensure cleanup even if stopping the WireMock server fails.
  • Added a regression test to verify that context entries can be removed.

Expected Result

Closed ApplicationContexts are no longer retained by Store after the shutdown cleanup executes.

Testing

  • Reviewed the implementation and identified the root cause.
  • Added a regression test for Store cleanup.
  • Full Maven build and test execution have not yet been verified.

Related Issue

Closes #214

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)

1 participant