I've been working on a Node application hosted with Azure App Service that is mostly responsible for forwarding requests to a database server.
Now I noticed that the application stops responding after a while.
I ran a test, sending 10 requests per second, forwarding all of them and responding with the response of the database. I did the same test with forwarding to google.com to make sure it is not the database server not responding.
At the moment. the application is pretty simple, using node express and express router. All it should do currently is, on request, send a request to google and return the response. After 10 to 30 seconds, it stops sending the requests to google (or to the database server), running in ETIMEDOUT errors after minutes of waiting if no timeout on the request set. After reaching that point, I have to wait several minutes until it is working again.
Here is the code (I tried with axios and http package of npm):
const DB_CLIENT = axios.create({
baseURL: 'http://www.google.com',
timeout: 5000,
})
router.use('/', async (req, res, next) => {
// Axios approach
const config = {
url: '/',
method: 'get',
}
DB_CLIENT.request(config)
.then(response => {
res.set(response.headers).status(response.status).send(response.data);
})
.catch(error => {
if (error.response) {
res.set(error.response.headers).status(error.response.status).send(error.response.data);
} else if (error.request) {
res.status(408).send();
} else {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
}
})
// http approach
// const options = {
// method: 'GET',
// host: 'www.google.com',
// }
// let request1 = http.request(options, response => {
// let body = '';
// response.on('data', (chunk) => {
// body += chunk;
// });
// response.on('end', () => {
// try {
// console.log("FINISHED")
// return res.status(response.statusCode).send(body);
// } catch (e) {
// return res.status(500).send();
// }
// });
// response.on('error', (err) => {
// console.log("ERROR IN RESPONSE")
// console.log(err)
// return res.status(500).send();
// });
// })
// request1.on('error', (err) => {
// console.log("ERROR IN REQUEST")
// console.log(err)
// res.status(408).send();
// })
// request1.end();
// setTimeout(() => {
// request1.destroy();
// }, 5000)
})
The App service is using Node 18. Switching between "always on: on/off" and http1.1/http2 did not have any effect.
The service plan is Standard S1, but switching to another plan also did not have any effect.
On localhost everything is working fine.