{"record":{"id":"aaa64dfeb72db0dc","repo":"apolloconfig/apollo","slug":"write-namespace-error","errorCode":null,"errorMessage":"Write namespace error. {}","messagePattern":"Write namespace error\\. (.+?)","errorType":"exception","errorClass":"ServiceException","httpStatus":500,"severity":"error","filePath":"apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java","lineNumber":306,"sourceCode":"        synchronized (zipOutputStream) {\n          String appId = configBO.getAppId();\n          String clusterName = configBO.getClusterName();\n          String namespace = configBO.getNamespace();\n          String configFileContent = configBO.getConfigFileContent();\n          ConfigFileFormat configFileFormat = configBO.getFormat();\n\n          String configFileName =\n              ConfigFileUtils.toFilename(appId, clusterName, namespace, configFileFormat);\n          String filePath = ignoreUserDir\n              ? ConfigFileUtils.genNamespacePathIgnoreUser(appId, configBO.getEnv(), configFileName)\n              : ConfigFileUtils.genNamespacePath(configBO.getOwnerName(), appId, configBO.getEnv(),\n                  configFileName);\n\n          writeToZip(filePath, configFileContent, zipOutputStream);\n        }\n      } catch (IOException e) {\n        logger.error(\"Write error. {}\", configBO);\n        throw new ServiceException(\"Write namespace error. {}\", e);\n      }\n    };\n\n    configBOStream.forEach(configBOConsumer);\n  }\n\n  private void writeClusterInfoToZip(Env env, App app, List<ClusterDTO> exportClusters,\n      ZipOutputStream zipOutputStream) {\n    final Consumer<ClusterDTO> clusterConsumer = cluster -> {\n      try {\n        synchronized (zipOutputStream) {\n          String fileName = ConfigFileUtils.genClusterInfoPath(app, env, cluster);\n          String content = gson.toJson(cluster);\n\n          writeToZip(fileName, content, zipOutputStream);\n        }\n      } catch (IOException e) {\n        logger.error(\"Write error. {}\", cluster);","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/apolloconfig/apollo/blob/d95fc18d112589efc09ddcbe1507047584d55251/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java#L288-L324","documentation":"Thrown by ConfigsExportService when writing a namespace configuration file (properties/xml/yml etc.) into the export ZipOutputStream fails with an IOException. This occurs in the configBO consumer that iterates over ConfigBO objects, generates the file path via ConfigFileUtils, and calls writeToZip. The ServiceException wraps the IOException and terminates the export.","triggerScenarios":"Exporting namespace configs where writeToZip() hits an I/O error: the OutputStream backing the response is closed, the zip entry path is invalid, or the stream was finished. The forEach over configBOStream drives sequential writes under no external synchronization beyond the method-level flow.","commonSituations":"Large number of namespaces causing the response to exceed proxy timeout; client disconnect during export; the generated file path contains characters invalid for ZipEntry names; disk pressure on the server.","solutions":["Check the underlying IOException in portal logs — the preceding 'Write error. {configBO}' line identifies which namespace failed.","Ensure the HTTP client/proxy (nginx, load balancer) allows sufficient response time and body size for large exports.","Verify the OutputStream passed to the export method is open and not prematurely closed by a filter or interceptor.","If exporting a specific app, reduce scope or export per-environment to avoid streaming too much data at once."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  configsExportService.exportNamespaces(zipOutputStream, configBOs);\n} catch (ServiceException e) {\n  log.error(\"Namespace export failed at I/O level\", e);\n  // surface a user-friendly message about export interruption\n  throw e;\n}","preventionTips":["Ensure the response OutputStream stays open for the entire export duration.","Test exports with a small number of namespaces first to validate the pipeline.","Monitor network stability between client and portal during large exports."],"tags":["apollo-portal","config-export","io","zip","namespace","service-exception"],"backgroundTag":null,"analyzedSha":"d95fc18d112589efc09ddcbe1507047584d55251","analyzedAt":"2026-08-14T04:00:05.477Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}