我看到的情况是,在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();
});
});
到目前为止,它按预期工作。