MyCATApache/Mycat-Server · error

write file err " + e

Error message

write file err " + e

What it means

ConfFileHandler.upLoadConfigFile writes an uploaded config file's bytes to a temp file in the MyCat conf directory. If any exception occurs while opening or writing the file, it logs a warning and replies to the manager client with a 'write file err <exception>' error message instead of applying the config. The exception text is passed straight through to the client.

Solutions

  1. Read the exception detail in the manager response; fix that cause first (usually permissions on the conf directory).
  2. chown/chmod the MyCat conf directory so the running user can write (e.g. chown -R mycat:mycat conf).
  3. Check free disk space and quota on the partition holding conf.
  4. Retry the upload after fixing; verify the file content is valid before applying.

Example fix

// shell fix
// before: drwxr-x--- root root /opt/mycat/conf
// after:
// chown mycat:mycat /opt/mycat/conf && chmod u+rwx /opt/mycat/conf
Defensive patterns

Strategy: try-catch

Validate before calling

File dir = new File(confPath).getParentFile();
if (!dir.isDirectory() || !dir.canWrite()) return "conf dir not writable: " + dir;
if (fileData == null || fileData.length == 0) return "empty upload payload";

Try / catch

// manager client side: parse the OK/ERR packet
if (resp.startsWith("write file err")) {
  logger.error("config upload failed: {}", resp.substring("write file err".length()));
}

Prevention

When it happens

Trigger: Uploading a config file via the manager port when the target directory is not writable, the disk is full, the temp file cannot be created, or the upload payload is bad.

Common situations: MyCat process lacks write permission on the conf directory, running in a read-only container filesystem, disk quota exceeded, or uploading to a wrong/unwritable configured file path.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/a31d067a599cd3ed. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/manager/handler/ConfFileHandler.java:207

		LOGGER.info("Upload Daas Config file " + fileName + " ,content:"
				+ content);
		String tempFileName = System.currentTimeMillis() + "_" + fileName;
		File tempFile = new File(SystemConfig.getHomePath(), "conf"
				+ File.separator + tempFileName);
		BufferedOutputStream buff = null;
		boolean suc = false;
		try {
			byte[] fileData = content.getBytes("UTF-8");
			if (fileName.endsWith(".xml")) {
				checkXMLFile(fileName, fileData);
			}
			buff = new BufferedOutputStream(new FileOutputStream(tempFile));
			buff.write(fileData);
			buff.flush();

		} catch (Exception e) {
			LOGGER.warn("write file err " + e);
			return showInfo(c, buffer, packetId, "write file err " + e);

		} finally {
			if (buff != null) {
				try {
					buff.close();
					suc = true;
				} catch (IOException e) {
					LOGGER.warn("save config file err " + e);
				}
			}
		}
		if (suc) {
			// if succcess
			File oldFile = new File(SystemConfig.getHomePath(), "conf"
					+ File.separator + fileName);
			if (oldFile.exists()) {
				File backUP = new File(SystemConfig.getHomePath(), "conf"
						+ File.separator + fileName + "_"

View on GitHub (pinned to 65f8d8beb7)