javascript - 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,任何帮助表示赞赏。
解决方案
对于有此问题且可能正在使用其他应用程序的人,一般回答问题(而不是让您切换到其他工具):
RangeError [ERR_CHILD_PROCESS_STDIO_MAXBUFFER]:超出标准输出最大缓冲区长度
该问题是由您的命令向 stdout 或 stderr 发送大量数据(超过 1MB)引起的。
为 process.exec 的节点文档增加maxBuffer
exec() 中的选项
exec(someCommand, {
maxBuffer: 5 * 1024 * 1024,
})
推荐阅读
- python - Python SkLearn Gradient Boost Classifier Sample_Weight Clarification
- c# - 从缓存中读取所有值
- python - pywinauto:遍历窗口中的所有控件
- python - 无法将 url 给定的变量传递给路由的回调函数和重定向问题
- jakarta-ee - 是否必须在 Java 中使用 JMS 实施 AWS SQS?
- javascript - 通过window.prompt在特定字段中将一些数据发布到mysql数据库(代码运行不正常)
- java - 如何使用java分隔数组列表中的对象
- firebase - 从 Firebase 获取数据
- javascript - 在函数内部调用外部声明的变量
- materialize - materializecss中的多个链接下拉问题