so I have my backend locally right now and I have an EC2 instance that has the API there. Timeout happens around 2 minutes after some request, my guess is that server.timeout is set to 2 minutes but I don’t know how to change it in my code.
Code for the API:
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const app = express();
app.use(cors());
app.use(bodyParser.json({limit: '30mb'}))
app.use(bodyParser.urlencoded({ limit: '30mb', extended: true }));
app.post('/calculate', async (req, res) => {
POST CODE HERE
});
app.listen(3000, () => {
console.log(`App listening on port 3000`);
});
Here is how I’m sending a file/data: I have an array called batchRequests, which lets say at the moment will have 5 batch requests
batchRequests.push(fetch('ip/calculate', {
method: 'POST',
body: JSON.stringify({file}),
headers: { 'Content-Type': 'application/json','Access-Control-Allow-Headers': '*',
'Access-Control-Allow-Origin': '*' },
}));
after this I send all batched requests concurrently with Promise
const batchResponses = await Promise.all(batchRequests);
requests.push(...batchResponses);
The error I’m getting on EC2 node is:
BadRequestError: request aborted
at IncomingMessage.onAborted (/home/ec2-user/project/node_modules/raw-body/index.js:245:10)
at IncomingMessage.emit (node:events:519:28)
at IncomingMessage._destroy (node:_http_incoming:224:10)
at _destroy (node:internal/streams/destroy:121:10)
at IncomingMessage.destroy (node:internal/streams/destroy:83:5)
at abortIncoming (node:_http_server:797:9)
at socketOnClose (node:_http_server:791:3)
at Socket.emit (node:events:531:35)
at TCP.<anonymous> (node:net:338:12)
The erorr I’m getting locally is:
node:internal/deps/undici/undici:11730
Error.captureStackTrace(err, this);
^
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11730:11)
at async Promise.all (index 9)
at async D:projectbackend.js:49:32 {
cause: SocketError: other side closed
at Socket.onSocketEnd (node:internal/deps/undici/undici:8280:26)
at Socket.emit (node:events:526:35)
at endReadableNT (node:internal/streams/readable:1589:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'UND_ERR_SOCKET',
socket: {
localAddress: '192.168.100.2',
localPort: 62485,
remotePort: 3000,
remoteFamily: 'IPv4',
timeout: undefined,
bytesWritten: 2300660,
bytesRead: 277
}
}
}
packages, just in case:
"dependencies": {
"body-parser": "^1.20.2",
"cors": "^2.8.5",
"express": "^4.19.2"
}
Node version: v20.14.0
I tried putting: res.socket.setTimeout(0);
at the first line of the api post call but it didn’t work.