首页 > 解决方案 > ChildProcessError:超出标准输出最大缓冲区长度

问题描述

我们有以下代码(不要问我为什么......即使作为 none-javascript dev 它对我来说看起来并不漂亮),在 Kubernetes 升级后会引发错误:

module.exports.getReplicationControllers = async function getReplicationControllers(namespace) {
  const kubeConfig = (await getNamespacesByCluster()).get(namespace);
  if (!kubeConfig) throw new Error(`No clusters contain the namespace ${namespace}`)
  const kubeConfigEscaped = shellEscape([kubeConfig]);

  const namespaceEscaped = shellEscape([namespace]);
  const result = await cpp(`kubectl --kubeconfig ${kubeConfigEscaped} get replicationcontrollers -o json -n ${namespaceEscaped}`);
  console.error(result.stderr);
  /** @type {{items: any[]}} */
  const resultParsed = JSON.parse(result.stdout);
  const serviceNames = resultParsed.items.map((item) => item.metadata.name);
  return serviceNames;
}

ChildProcessError: stdout maxBuffer length exceeded kubectl --kubeconfig /kubeconfig-staging get replicationcontrollers -o json -n xxx(退出错误代码 ERR_CHILD_PROCESS_STDIO_MAXBUFFER)

到目前为止我尝试过的是:

  const result = await cpp(`kubectl --kubeconfig ${kubeConfigEscaped} get replicationcontrollers -o=jsonpath='{.items[*].metadata.name}' -n ${namespaceEscaped}`);
  console.error(result.stderr);
  const serviceNames = result.split(' ');
  return serviceNames;

哪个返回

TypeError:result.split 不是函数

我不是超级精通 JavaScript,任何帮助表示赞赏。

标签: javascriptnode.jskubernetes

解决方案


对于有此问题且可能正在使用其他应用程序的人,一般回答问题(而不是让您切换到其他工具):

RangeError [ERR_CHILD_PROCESS_STDIO_MAXBUFFER]:超出标准输出最大缓冲区长度

该问题是由您的命令向 stdout 或 stderr 发送大量数据(超过 1MB)引起的。

为 process.exec 的节点文档增加maxBufferexec() 中的选项

exec(someCommand, {
  maxBuffer: 5 * 1024 * 1024,
})

推荐阅读