node.js - 在 end() 之后销毁套接字有什么影响?
问题描述
我看到的情况是clientError
,客户端不确认 FIN,即
httpServer.on('clientError', (error, socket) => {
socket.write(stringifyHttpResponseMessage(400, {connection: 'close'}, 'OK'));
socket.end();
setTimeout(() => {
// socket remains writable.
// What is the risk of calling `socket.destroy()` here?
socket.destroy();
}, 1000);
});
结果,一连串的客户端错误导致打开套接字,直到达到相关的空闲套接字超时(这是相当高的)。
之后销毁套接字有什么影响end()
?
解决方案
我面临着同样的问题。为了解决这个问题,我在响应写入后销毁了套接字,而不是结束套接字。这是我所做的一个例子。
httpServer.on('clientError', (error, socket) => {
socket.write(stringifyHttpResponseMessage(400, {connection: 'close'}, 'OK'), 'utf8', () => {
socket.destroy();
});
});
到目前为止,它按预期工作。
推荐阅读
- delphi - 如何通过选择 DBGrid Main Category 显示相关子类别
- json - 如果解码器失败使用其他解码器
- c# - 在 ModalPopupExtender 中编辑 Gridview 后无法加载 Viewstate 错误
- django - 如何将此 SQL 查询“翻译”为 django 中的查询集
- python - 总结所有正值和所有负值 Pandas
- macos - 我应该把 Pyqt4 脚本生成的文件放在哪里?
- amazon-ec2 - 带有 HTTPS 侦听器的 AWS 弹性负载均衡器。最终用户浏览器认为网站是安全的?
- sqlite - 我们如何将日期插入 SQLite 数据库
- html - CSS边框半径不适用于UIwebview
- matlab - fmincon 在输入参数上抛出错误