我正在尝试为我的编码项目的 Mineflayer API 制作一个 Web 服务器。它使用 render.com 上的免费计划托管,我使用 cron 作业来保持它的唤醒状态。但是,当我向它发送机器人创建请求时,它给出了此错误,然后继续执行:
Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
{
errno: -104,
code: 'ECONNRESET',
syscall: 'read'
}
我尝试在代码中查找错误,但没有发现任何错误。服务器通过
switch
语句来确定采取哪条路径,并触发此语句:
case "create":
let [username, ip, port] = data.split(","); // For now, we only support offline mode.
let id = crypto.randomBytes(32).toString('hex');
let bot = mineflayer.createBot({username: username || `Bromine_${id.slice(0, 8)}`, host: ip, port: (port || 25565)});
bot.messages = [];
bot.on("message", function(msg, pos) {this.messages.push({jsonMsg: msg, position: pos})});
bots[id] = {bot: bot};
var response = {success: true, id: id};
break;
错误消息有时会更长,并且可能包含更多信息:
Error: write ECONNRESET
at afterWriteDispatched (node:internal/stream_base_commons:160:15)
at writeGeneric (node:internal/stream_base_commons:151:3)
at Socket._writeGeneric (node:net:962:11)
at Socket._write (node:net:974:8)
at writeOrBuffer (node:internal/streams/writable:392:12)
at _write (node:internal/streams/writable:333:10)
at Writable.write (node:internal/streams/writable:337:10)
at Framer.ondata (/opt/render/project/src/node_modules/minecraft-protocol/node_modules/readable-stream/lib/internal/streams/readable.js:705:22)
at Framer.emit (node:events:517:28)
at addChunk (/opt/render/project/src/node_modules/minecraft-protocol/node_modules/readable-stream/lib/internal/streams/readable.js:321:12)
{
errno: -104,
code: 'ECONNRESET',
syscall: 'write'
}
由于某种原因,它又可以工作了。它现在起作用的最可能的原因是因为我让它等到它生成后再完成请求。