{"record":{"id":"870d4ff5dc5ec6ec","repo":"MyCATApache/Mycat-Server","slug":"er-yes","errorCode":"ER_YES","errorMessage":"white host set success ,but write to file failed :\" + e.getMessage()","messagePattern":"white host set success ,but write to file failed :\" \\+ e\\.getMessage\\(\\)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main/java/io/mycat/manager/response/ShowWhiteHost.java","lineNumber":155,"sourceCode":"        \ti++;  \r\n        \tUserConfig uc = MycatServer.getInstance().getConfig().getUsers().get(user);\r\n            if (null == uc) {\r\n            \tc.writeErrMessage(ErrorCode.ER_YES, \"user doesn't exist in host.\");\r\n                return; \r\n            }\r\n            if (uc.getSchemas() == null || uc.getSchemas().size() == 0) {\r\n            \tc.writeErrMessage(ErrorCode.ER_YES, \"host contains one root privileges user.\");\r\n                return;                 \r\n            }\r\n            userConfigs.add(uc);\r\n          }   \r\n        }  \r\n       if (MycatServer.getInstance().getConfig().getFirewall().addWhitehost(host, userConfigs)) {\r\n    \t   try{\r\n               FirewallConfig.updateToFile(host, userConfigs);\r\n           }catch(Exception e){\r\n        \t   LOGGER.warn(\"set while host error : \" + e.getMessage());\r\n        \t   c.writeErrMessage(ErrorCode.ER_YES, \"white host set success ,but write to file failed :\" + e.getMessage());\r\n           }\r\n    \t   \r\n           ok.packetId = 1;\r\n           ok.affectedRows = 1;\r\n           ok.serverStatus = 2;        \r\n    \t   ok.message = \"white host set to succeed.\".getBytes();\t\r\n           ok.write(c);  \t \r\n           \r\n       }\r\n       else {\r\n           c.writeErrMessage(ErrorCode.ER_YES, \"host duplicated.\");\r\n       }\r\n\t}\t\r\n\t\r\n\t\r\n\t\r\n}\r\n","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/MyCATApache/Mycat-Server/blob/65f8d8beb752f935752f2a0eec0ab017facab9ef/src/main/java/io/mycat/manager/response/ShowWhiteHost.java#L137-L173","documentation":"ShowWhiteHost.setHost adds a white host to the in-memory firewall config (which succeeds), then tries to persist it via FirewallConfig.updateToFile. If persistence throws, the client gets an ER_YES error message saying the white host was set in memory but could not be written to the config file — leaving runtime state and file state inconsistent until restart loses the change.","triggerScenarios":"Executing the manager 'white host=...' statement when the myid/conf configuration file cannot be written: unwritable directory, missing file, disk full, or XML write failure.","commonSituations":"MyCat running as a user without write access to the conf directory, read-only container filesystem, or a corrupted/locked server.xml-style config preventing persistence.","solutions":["Fix the underlying write failure shown in e.getMessage() (typically permissions on the conf directory or the config file).","chown/chmod the conf directory and config file to the MyCat process user, then re-issue the white host command.","Verify free disk space on the conf partition.","If the in-memory change is acceptable short-term, export/persist the config manually and restart MyCat to confirm the host survives."],"exampleFix":"// shell fix\n// before: -rw-r--r-- root root /opt/mycat/conf/server.xml\n// after:\n// chown mycat:mycat /opt/mycat/conf/server.xml /opt/mycat/conf && chmod u+rw /opt/mycat/conf/server.xml","handlingStrategy":"try-catch","validationCode":"File confDir = new File(confPath).getParentFile();\nif (!confDir.canWrite()) throw new IllegalStateException(\"cannot persist white host, conf dir unwritable: \" + confDir);","typeGuard":null,"tryCatchPattern":"// after issuing 'white host=...' on the manager port\nif (resp.contains(\"write to file failed\")) {\n  logger.warn(\"whitelist active in memory only; fix conf write perms and re-apply: {}\", resp);\n}","preventionTips":["Fix conf directory permissions before runtime firewall changes.","Remember the change is memory-only if persistence fails — re-apply after restart.","Keep config files owned by the MyCat runtime user."],"tags":["manager","firewall","white-host","config-persistence"],"backgroundTag":"file-write-failed","analyzedSha":"65f8d8beb752f935752f2a0eec0ab017facab9ef","analyzedAt":"2026-09-11T00:12:21.696Z","contentChangedAt":"2026-09-11T00:12:21.696Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}