EBADF = Bad file descriptor。嘗試對已關閉、無效或錯誤類型的文件描述符進行讀寫/關閉操作。
const fd = fs.openSync(path, 'w');
emitter.on('data', data => fs.write(fd, data)); // 異步寫入
// 某處提前關閉
setTimeout(() => fs.closeSync(fd), 10);
// 但 emitter 仍在觸發 data 事件 → EBADF, write
emitter.on('end', () => {
fs.closeSync(fd);
fs.closeSync(fd); // 第二次調用 → EBADF, close
});
錯誤信息更友好,會顯示調用棧,直接定位代碼修復。
`child_process.exec/execFile/spawnSync/execSync` 默認 `maxBuffer: 200KB`,子進程輸出超過此限制即拋錯。
const { exec } = require('child_process');
exec('big-command', {
encoding: 'utf8',
maxBuffer: 10 * 1024 * 1024, // 10MB
timeout: 0,
killSignal: 'SIGTERM'
}, (err, stdout, stderr) => { ... });
// 或使用流式處理,避免緩衝
const { spawn } = require('child_process');
const child = spawn('big-command');
let output = '';
child.stdout.on('data', chunk => output += chunk);
child.on('close', code => { console.log(output); });
前端連接器轉發消息到後端服務器失敗,RPC 調用鏈中找不到目標服務器實例。
// servers.json 正確示例
{
"connector": [{ "id": "connector-1", "host": "127.0.0.1", "port": 3050, "frontend": true }],
"game": [{ "id": "game-1", "host": "127.0.0.1", "port": 3051, "frontend": false }] // 必須為 false
}