I have a cronjob that runs once a day and per each row of a table
it fetches external api and updates our db
(in parallel).
Cronjob fails on Vercel production (stucks without final error logs).
It works perfect If running as api route from my PC, all 600 rows are updated.
It only works good on Vercel production if we try to run it maximum for 50 rows,
this way all is good and we see the logs.
What we try to do:
- Show ‘Starting cronjob’ log
- map through N db rows (currently 650) and create promises, in each we fetch ext. api and update db
- await Promise.allSettled(promises)
- Show ‘Ending cronjob’ log
What we see on Vercel:
- ‘Starting cronjob’ log
- updating N db rows with errors*
- stucks on some row without final log (‘Ending cronjob’)
errors* -fetch failed at node:internal/deps/undici/undici:13178:13 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async T (/var/task/.next/server/chunks/83.js:1:10610) at async /var/task/.next/server/app/api/cron-update-cashtags-prices/route.js:1:3870 at async Promise.allSettled (index 499) at async /var/task/.next/server/app/api/cron-update-cashtags-prices/route.js:1:4367 at async /var/task/.next/server/chunks/197.js:13:50753 at async /var/task/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:34666 at async eS.execute (/var/task/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:25813) at async eS.handle (/var/task/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:6:35920) { [cause]: AggregateError [EMFILE]: at internalConnectMultiple (node:net:1118:18) at internalConnectMultiple (node:net:1186:5) at internalConnectMultiple (node:net:1186:5) at defaultTriggerAsyncIdScope (node:internal/async_hooks:464:18) at GetAddrInfoReqWrap.emitLookup [as callback] (node:net:1522:7) at GetAddrInfoReqWrap.onlookupall [as oncomplete] (node:dns:132:8) at GetAddrInfoReqWrap.callbackTrampoline (node:internal/async_hooks:130:17) { code: 'EMFILE', [errors]: [ [Error], [Error] ] } }
We can not get what’s actually happening here. Why don’t we see the final log, why it works locally and doesn’t on Vercel, why we see no clear error.
Thanks in advance! Please let me know if more details needed