Reputation: 6888
I am getting a connection reset error. I am fairly certain this is coming from a long running REST request, that is timing out.
{ [Error: socket hang up] code: 'ECONNRESET' }
Is there a way to disable request timeouts in Koa, so that I can test this hypothesis?
I am running node version 5.x, koa 0.10, centOs 6
Upvotes: 6
Views: 10284
Reputation: 81
if want to set timeout for application server:
let app = new Koa();
let server=app.listen(3000);
server.timeout=5*60*1000;
if for per request, as @m1uan saying:
router.get("/path",async (ctx)=>{
ctx.request.socket.setTimeout(5 * 60 * 1000);
})
Upvotes: 5
Reputation: 558
It seems your request take longer than default Koa timeout. Default Koa timeout is 2 minutes
I had similar problem one request take more time than 2 minutes.
I was inspirate by zeronone
commend in this post, and finally this line helped to me
ctx.request.socket.setTimeout(5 * 60 * 1000);
so whole code in router could look like
router.post('/long-request', async (ctx) => {
// set timeout to 5 minutes
ctx.request.socket.setTimeout(5 * 60 * 1000);
// do some stuf what take long time
// but less than 5 minutes
});
I really don't recommend do request what take longer than 1 minute, ideally run the heavy stuff on separate process and by other request just check if is the work done.
So that could be good just for testing purposes
Upvotes: 6