Azure Web App stops sending requests

Niklas George 5 Reputation points
2023-06-28T14:40:12.4966667+00:00

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.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Niklas George 5 Reputation points
    2023-06-29T11:43:58.6633333+00:00
    1 person found this answer helpful.
    0 comments No comments

  2. Grmacjon-MSFT 19,491 Reputation points Moderator
    2023-06-29T20:07:02.4566667+00:00

    Hi @Niklas George ,

    We're glad that you were able to resolve your issue and thank you for posting your solution so that others experiencing the same thing can easily reference this!

    Since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others ", I'll repost your solution in case you'd like to "Accept " the answer.

    Issue:

    -You had an issue with your Node application hosted on Azure App Service using Node Express and Express Router

    -You noticed the application stops responding after a while, even when forwarding requests to Google or a database server and it returned ETIMEDOUT errors. Localhost testing showed no issues.

    -The problem persists despite changing the service plan and App Service settings.

    Solution:

    Using the npm agentkeepalive package solved the issue as described in these two Azure docs:

    -Troubleshooting intermittent outbound connection errors in Azure App Service

    -Best practices and troubleshooting guide for node applications on Azure App Service Windows

    Thanks again for taking the time to share your solution.

    Best,

    Grace

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.