Skip to content

COLDBOX-1471 Unloading a module leaves parts of it behind - #732

Open
homestar9 wants to merge 2 commits into
ColdBox:developmentfrom
homestar9:fix/module-unload-leftovers
Open

homestar9 wants to merge 2 commits into
ColdBox:developmentfrom
homestar9:fix/module-unload-leftovers

Conversation

@homestar9

@homestar9 homestar9 commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

ModuleService.unload() and unloadAll() did not fully clean up after a module:

  • Interceptors kept listening. They are registered as Name@moduleName but were unregistered as Name. They are now unregistered with the name they were registered with.
  • The module router kept listening. It is registered as the interceptor Router@moduleName and was never unregistered. It is now.
  • Aliases stayed registered. The names in this.aliases stayed in the modules setting and the config cache, pointing at the unloaded module. They are now removed.
  • An executor owned by someone else was shut down. If an executor a module declares already exists, the module just uses it. But unload() shut down every executor the module declared, including one the application or another module created first. ColdBox now remembers which executors each module created and only shuts those down.
  • unloadAll() unloaded a module once per alias. Aliases are extra keys pointing at the same module, so onUnload() ran more than once. Alias keys are now skipped, except a module's own name, which some modules also list as an alias.

Jira Issues

https://ortussolutions.atlassian.net/browse/COLDBOX-1471

Part of https://ortussolutions.atlassian.net/browse/COLDBOX-1478

Type of change

  • Bug Fix

Checklist

  • My code follows the style guidelines of this project cfformat
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Tests

  • tests/specs/web/services/ModuleServiceUnloadTest.cfc (new): one spec for each problem above. The test module in tests/resources/unloadfixtures/unloadMain/ declares an interceptor, a router, an alias and two executors.

The 5 specs for the five problems fail on the 8.3.0 code. The sixth, for a module that lists its own name as an alias, passes on 8.3.0 and guards against the mistake in my first version of the fix. Every spec passes on BoxLang, Lucee 5 and 6, and Adobe 2023 and 2025 (GitHub checks).

unload() left parts of a module registered and could remove something the module did not own:

- Module interceptors are registered as Name@module but were unregistered as Name, so they kept listening.
- The module router is registered as an interceptor and was never unregistered.
- Alias keys stayed in the modules setting and the module config cache.
- Every executor a module declared was shut down, even one the application or another module had created first under the same name. Only executors the module itself created are shut down now.
- unloadAll() ran unload() once for the module name and once more for each alias, so onUnload() ran more than once.

Each fix has a spec that fails without it.
@homestar9
homestar9 marked this pull request as ready for review October 27, 2026 22:25
… its own name as an alias

The alias check skipped any key found in the module's own aliases. A module whose alias equals its own name (e.g. a module installed under its alias) was then never unloaded, not even at application shutdown. A key of the module registry is a real module name, so it is never skipped.
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.

1 participant