Random socket timeout errors - Node.JS Azure Function

Ken Faubel 26 Reputation points
2021-12-23T12:52:15.963+00:00

I have an Azure Function with about 10 timer triggers. Each wakes up, makes a REST GET call to some resource, does some work with it and finishes. The triggers are implemented with nodejs v14 and use axios.

I have set a timeout of 5000 and some of the time it works fine and sometimes it times out (Error: timeout of 5000ms exceeded). I added a retry on failure and the second attempt frequently works. I am pulling data from a bunch of sources including the National Weather Service, NOAA, Google, MLB, NASA and others. The NWS can fail > 20% of the time with a similar success rate on retries.

Given that it works when I run the functional locally and most of the time it works fine when deployed, I think the code is fine.

// Check for new or updated alerts every hour
const alertsURL = `https://api.weather.gov/alerts/active?point=${lat},${lon}`;
try {
    response = await axios.get(alertsURL, 
        {
            headers: {
                "Content-Encoding": "gzip", 
                "User-Agent": userAgent
            }, 
            timeout: 5000
        }
    );
} catch (e) {
    this.logger.error(`ForecastData: alert: ${e}`);
}

With ~10 triggers all firing on different intervals, I am wondering if there is some kind of outbound connection limit that I hit every once in a while. I checked the function configuration options and I did not see anything.

Any help would be appreciated.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
{count} vote

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.