我正在尝试为我的应用程序编写一个测试,其中我使用了 express-brute以防止暴力攻击。
我有以下测试:
it('should return 429 status after 1000 attempts', function (done) {
this.timeout(5000);
var counter = 0;
var makeRequest = function (count, done) {
counter++;
request(app)
.post('/login')
.send({ username: 'a+' + count + '@b.com', password: 'wrong' + count })
.end(function (err, res) {
if (err) {
console.log('failed request #', counter);
return done(err);
}
if (counter < 1001) {
makeRequest(counter, done);
}
else {
res.header.location.should.equal('/account/login');
res.statusCode.should.equal(429);
done();
}
});
}
makeRequest(counter, done);
});
这会引发错误:
Error: socket hang up sometimes it is Error: read ECONNRESET
它总是围绕连接#225
相同的测试(只有 20 个左右的请求)工作正常(如果我更改我的express-brute 配置)
什么原因导致它出错?
我是否没有正确关闭/处理连接?
最佳答案
关于node.js - 在 Node 应用程序上触发许多请求进行测试,导致套接字挂起/ECONNRESET 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22272907/