My node app is giving out this error. It looks like an API error.
{ Error: getaddrinfo EAI_AGAIN www.googleapis.com:443
20|Music | at Object.exports._errnoException (util.js:1022:11)
20|Music | at errnoException (dns.js:33:15)
20|Music | at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
20|Music | code: 'EAI_AGAIN',
20|Music | errno: 'EAI_AGAIN',
20|Music | syscall: 'getaddrinfo',
20|Music | hostname: 'www.googleapis.com',
20|Music | host: 'www.googleapis.com',
20|Music | port: 443 }
20|Music | { Error: getaddrinfo EAI_AGAIN www.googleapis.com:443
20|Music | at Object.exports._errnoException (util.js:1022:11)
20|Music | at errnoException (dns.js:33:15)
20|Music | at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
20|Music | code: 'EAI_AGAIN',
20|Music | errno: 'EAI_AGAIN',
20|Music | syscall: 'getaddrinfo',
20|Music | hostname: 'www.googleapis.com',
20|Music | host: 'www.googleapis.com',
20|Music | port: 443 }
Further details:
Thanks!
Can you post the code that's calling this?
Here is an async function I wrote. I think the error happens when I'm loading a lot request with this function.
const google = require('googleapis');
const youtube = google.youtube('v3');
const async = require('async');
async.each(videos, function(video, cb) {
if (video.id.kind === PLAYLIST_TYPE) {
youtube.playlists.list({
key: apiKey,
id: video.id.playlistId,
part: 'contentDetails'
}, (err, response) => {
if (err) {
console.log(err);
cb(err);
}
video.itemCount = response.videos[0].contentDetails.itemCount;
cb();
});
}
});
Yeah - sometimes that happens with node when you spawn too many functions at the same time that try opening a connection. I suggest using an async.queue to throttle the number of connections you create at one time. For example, something like this (untested):
let q = async.queue((video, callback) => {
if (video.id.kind === PLAYLIST_TYPE) {
youtube.playlists.list({
key: apiKey,
id: video.id.playlistId,
part: 'contentDetails'
}, (err, response) => {
if (err) {
console.log(err);
cb(err);
}
video.itemCount = response.videos[0].contentDetails.itemCount;
cb();
});
}
}, 10);
q.push(videos);
@JustinBeckwith if this is a Node limitation, is it worth bringing up with Node itself (or at least asking them to clarify their error message)?
From Node official documentation: Though the call to dns.lookup() will be asynchronous from JavaScript's perspective, it is implemented as a synchronous call to getaddrinfo(3) that runs on libuv's threadpool.
Thus, you can increase the number of workers in the libuv's thread pool by setting process.env.UV_THREADPOOL_SIZE in your node program. The default number is 4, the max number you can set is 128.
Thanks! Though - this is just the first place the code could fall down. After DNS, it's active connections. Then it's API rate limiting. Any time you're making (n) simultaneous network requests, where (n) can be a list unbounded in size... I really think a queue is a good idea.
Closing this up since there's likely nothing to be done on our side. Let us know if the async queue doesn't help!
Most helpful comment
From Node official documentation:
Though the call to dns.lookup() will be asynchronous from JavaScript's perspective, it is implemented as a synchronous call to getaddrinfo(3) that runs on libuv's threadpool.Thus, you can increase the number of workers in the libuv's thread pool by setting
process.env.UV_THREADPOOL_SIZEin your node program. The default number is 4, the max number you can set is 128.