MyCATApache/Mycat-Server · error · ConfigException
host duplicated
Error message
host duplicated : ${host} What it means
XMLServerLoader.loadFirewall parses the <firewall><host> section of server.xml, which maps host patterns to allowed users. Each host value must not already be registered in the firewall's host table; if firewall.existsHost(host) is true while adding, it throws this ConfigException. Duplicate host entries would make whitelist enforcement ambiguous.
Solutions
- Open server.xml's <firewall> section and remove or merge duplicate host entries so each host/IP appears only once across all <host> elements
- If one host needs multiple users, list several users in the single host element's user attribute instead of duplicating the host
- Check comma-separated lists within one attribute for repeated values after trimming
- Restart MyCat after deduplicating
Example fix
// before <host host="10.0.0.1" user="user1"/> <host host="10.0.0.1" user="user2"/> // after <host host="10.0.0.1" user="user1,user2"/>
Defensive patterns
Strategy: validation
Validate before calling
// detect duplicate hosts in server.xml firewall section
Set<String> seen = new HashSet<>();
NodeList hs = doc.getElementsByTagName("host");
for (int i = 0; i < hs.getLength(); i++) {
for (String h : ((Element) hs.item(i)).getAttribute("host").split(",")) {
if (!seen.add(h.trim())) throw new IllegalStateException("Duplicate firewall host: " + h);
}
} Type guard
null
Try / catch
try {
serverLoader.load();
} catch (ConfigException e) {
LOG.error("Firewall host duplication in server.xml: " + e.getMessage());
throw new ConfigurationException("Each whitelisted host may appear only once", e);
} Prevention
- Whitelist each host once and group multiple users via the user attribute
- Trim and dedupe comma-separated host lists at generation time
- Diff-merge server.xml fragments carefully to avoid re-adding hosts
When it happens
Trigger: Loading server.xml at startup; a <host host="10.0.0.1"> element lists an IP/host that a previous <host> element (or an earlier entry in the same comma-separated list) already registered.
Common situations: Repeating the same IP in two <host> elements to grant different user groups; including the same host twice within one comma-separated host attribute; merging server.xml fragments that both whitelist the same host.
Understand the failure class
Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.
Related errors
- dataHost name duplicated!
- writeHost duplicated!
- readHost duplicated!
- [user: ] doesn't exist in [host: ]
- [host: ] contains one root privileges user
AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11).
Data as JSON: /api/errors/8a2b51453075467d.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/io/mycat/config/loader/xml/XMLServerLoader.java:152
* @date 2016/12/8
* @modifiedBy Hash Zhang
*/
private void loadFirewall(Element root) throws IllegalAccessException, InvocationTargetException {
NodeList list = root.getElementsByTagName("host");
Map<String, List<UserConfig>> whitehost = new HashMap<>();
Map<Pattern, List<UserConfig>> whitehostMask = new HashMap<>();
for (int i = 0, n = list.getLength(); i < n; i++) {
Node node = list.item(i);
if (node instanceof Element) {
Element e = (Element) node;
String hostStr = e.getAttribute("host").trim();
String userStr = e.getAttribute("user").trim();
String []hosts = hostStr.split(",");
for (String host : hosts) {
host = host.trim();
if (this.firewall.existsHost(host)) {
throw new ConfigException("host duplicated : " + host);
}
}
String []users = userStr.split(",");
List<UserConfig> userConfigs = new ArrayList<UserConfig>();
for(String user : users){
user = user.trim();
UserConfig uc = this.users.get(user);
if (null == uc) {
throw new ConfigException("[user: " + user + "] doesn't exist in [host: " + hostStr + "]");
}
if (uc.getSchemas() == null || uc.getSchemas().size() == 0) {
throw new ConfigException("[host: " + hostStr + "] contains one root privileges user: " + user);
}
userConfigs.add(uc);
}
for (String host : hosts) {
host = host.trim();
if (host.contains("*") || host.contains("%")) {View on GitHub (pinned to 65f8d8beb7)