使用正文解析器的Express App中的最大调用堆栈大小超出错误

时间:2015-12-29 04:28:17

标签: javascript node.js express body-parser

我只是偶尔会收到此错误,我实际上没有任何步骤在应用程序中复制它,除了尽可能多地尝试在应用程序中生成尽可能多的流量。仍然不确定这是一个中间件或其他完全问题。我目前在app中使用body-parser,按照他们的说明进行设置。

如果我使用Postman,当我打电话给 OPTIONS / server_url 时,我会收到此错误。当此错误触发时,它将始终为OPTIONS,POST和DELETE的所有网络请求生成此错误 - 这需要针对CORS相关的内容完成。无论出于何种原因,GET和PUT请求似乎都没有问题。

RangeError: Maximum call stack size exceeded
   at proxy (../node_modules/express/lib/router/index.js:643:8)
   at next (../node_modules/express/lib/router/index.js:206:14)
   at Layer.handle [as handle_request] (../node_modules/express/lib/router/layer.js:97:5)
   at ../node_modules/express/lib/router/index.js:277:22
   at param (../node_modules/express/lib/router/index.js:349:14)
   at param (../node_modules/express/lib/router/index.js:365:14)
   at Function.process_params (../node_modules/express/lib/router/index.js:410:3)
   at next (../node_modules/express/lib/router/index.js:271:10)
   at next (../node_modules/express/lib/router/route.js:121:14)
   at next (../node_modules/express/lib/router/route.js:125:14)
   at next (../node_modules/express/lib/router/route.js:125:14)
   at next (../node_modules/express/lib/router/route.js:125:14)
   at next (../node_modules/express/lib/router/route.js:125:14)
   at next (../node_modules/express/lib/router/route.js:125:14)
   at next (../node_modules/express/lib/router/route.js:125:14)
   at next (../node_modules/express/lib/router/route.js:125:14)

在经过多次尝试搞清楚之后,我很遗憾在这个问题的哪个地方开始。如果我重新启动我的应用程序,它将再次开始正常工作 - 直到我在应用程序中做得足够多,它再次触发此错误。另外,应用程序中的内存利用率与我所看到的一样正常,服务器仍然有足够的内存。

3 个答案:

答案 0 :(得分:1)

这个问题与一个调用next()并在之后进行大量操作的中间件有关。在process.nextTick()中包装下一个解决了现在的调用堆栈问题。我应该注意,使用node-inspector找到问题

答案 1 :(得分:1)

我解决了这个问题。

var bodyparser = require('body-parser');

而不是app.use(bodyparser.urlencoded({ extended: false })); 写这个

var urlencodedParser = bodyparser.urlencoded({ extended: false });

答案 2 :(得分:0)

它可能看起来像某个地方的内存泄漏或某个地方的某个无限循环或请求未完成(这可能不是真的,因为请求带有默认超时1000秒)。