While working with googleapis
library with a coworker, I’ve stumbled onto this error:
Uncaught GaxiosError Error: request to <gmail api url> failed, reason: connect EMFILE <xxx.xxx.xx.xxx:xxx> - Local (undefined:undefined)
at _request (/gmail-api/node_modules/gaxios/build/src/gaxios.js:149:19)
at processTicksAndRejections (<node_internals>/internal/process/task_queues:95:5)
gaxios.js:149
Process exited with code 1
It happened only if I tried to generate a list of promises to be used with Promise.all
:
const promises = emailList.map((email) => {
return this.gmailApi.users.messages.get({
userId: 'me',
id: email.id,
})
})
const resolvedPromises = await Promise.all(promises)
However, if instead I manually executed only the first 10 promises, without mapping each one to my promises
variable, it would work. It seems it only causes the error AFTER I iterate each promise with the .map
… My question is: Why does this happen? What is node doing behind the curtains?