Grails 7 Holders.config.merge() issue in tomcat when multiple Grails 7.1.0 Apps are deployed in apache-tomcat-10.1.50
- Dominant language
- Groovy
- Stars
- 2.9k
- Forks
- 975
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 92
Description
### Expected Behavior
We are encountering an issue with Holders.config.merge() in Grails 7.1.0 when multiple Grails applications are deployed on the same Apache Tomcat 10.1.50 instance.
The problem does not occur when only a single Grails application is deployed. The same code has been working reliably in Grails 6.x without any issues.
Environment
**Use Case**
Our application has a scheduled CRON job that periodically reloads application-specific configuration values from a database.
The reload process is designed to preserve the original application configuration and then merge it back after refreshing dynamic configuration values.
The workflow is:
1. Back up the original configuration (initialConfig) that contains values loaded from:
- application.groovy / application.yml
- External filesystem configuration
- Other startup configuration sources
2. Clear the current configuration using:
- Holders.config.clear()
3.Restore the original configuration using:
Holders.config.merge(initialConfig)
**Expected Behavior:**
After calling: **Holders.config.merge(initialConfig)** all configuration entries stored in **initialConfig** should be restored into Holders.config.
This behavior works correctly: in In Grails 6.x, whereas in Grails 7.1.0 it works when only a single application is deployed in Tomcat
if we deploy more than one Grails 7.1.0 **Holders.config.merge** does not correctly restore the configuration.
Instead, the application configuration appears to be lost or emptied, leaving **Holders.config** in an invalid state. As a result, application functionality dependent on configuration values ant it stops working
**Configuration Reload Logic**
static PropertySourcesConfig initialConfig = new PropertySourcesConfig()
backupInitialConfiguration()
Holders.config.clear()
// In Grails 7.1.0, when multiple applications are deployed in the same
// Tomcat instance, this call does not restore the configuration correctly.
Holders.config.merge(initialConfig)
//Backup Logic
public void backupInitialConfiguration() {
if (initialConfig?.size() == 0) {
Config config = Holders.config
Map configMap = [:]
for (def entry : config) {
configMap.put(entry.key, config.get(entry.key))
}
initialConfig = new PropertySourcesConfig(configMap)
}
}
### Actual Behaviour
Mentioned in above section
### Steps To Reproduce
It's mentioned in "Expected Behavior" Section
### Environment Information
Grails Version: 7.1.0
Tomcat Version: 10.1.50
Deployment Model: Multiple Grails applications deployed in the same Tomcat instance
Java Version: JDK 17 and Above
### Example Application
_No response_
### Version
7.1.0
Contributor guide
Research direction
Start with the reported reload logic around Holders.config.clear(), Holders.config.merge(initialConfig), and PropertySourcesConfig, comparing behavior between one and multiple Grails applications on Tomcat 10.1.50. Reproduce with Grails 7.1.0 and JDK 17 or newer; done means the original configuration from application.groovy, application.yml, external files, and other startup sources is restored for each deployed application.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100