我在MacOS中安排了一个节点脚本作为cronjob。我正在将cronjob的日志保存到一个文件中。当使用我在cronjob中使用的相同命令从外壳手动执行该脚本时,它会成功执行,但它会从cronjob中给出错误。
该脚本已使用snoowrap
请求从reddit获取顶级帖子。我认为这就是错误的来源。错误是:
RangeError: Maximum call stack size exceeded
at /Users/kiro/Documents/learns/myproj/node_modules/snoowrap/dist/objects/Listing.js:231:21
at tryCatcher (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/promise.js:547:31)
at Promise._settlePromise (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/promise.js:604:18)
at Promise._settlePromise0 (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/promise.js:649:10)
at Promise._settlePromises (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/promise.js:729:18)
at _drainQueueStep (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/async.js:93:12)
at _drainQueue (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/async.js:86:9)
at Async._drainQueues (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/async.js:102:5)
at Immediate.Async.drainQueues [as _onImmediate] (/Users/kiro/Documents/learns/myproj/node_modules/bluebird/js/release/async.js:15:14)
at processImmediate (node:internal/timers:466:21)
node:internal/process/promises:265
triggerUncaughtException(err, true /* fromPromise */);
我在crontab中使用的命令是~/Documents/learns/myproj/job.sh >> ~/Documents/learns/myproj/cron.log 2>&1
其中job.sh具有~/.nvm/versions/node/v16.14.0/bin/node ~/Documents/learns/myproj/build/index
这是代码中给出错误的部分
await this.redditClient
.getSubreddit(subreddit)
.getTop({ time: "day", limit: 400, count: 400 });
我也尝试传递--max-stack-size 32000
,但仍然出现相同的错误。
造成这种情况的原因是什么?我如何解决它?
1条答案
按热度按时间5lwkijsr1#
如果不看到您的代码,就很难说出来。我最好的猜测是,您在没有等待前一个函数完成的情况下启动了太多函数。尝试让您的代码同步运行,甚至更好地参见Call async/await functions in parallel