在Node.JS中创建产品时条带崩溃

时间:2018-04-23 17:21:22

标签: node.js express stripe-payments stripe-connect

我正在尝试使用stripe创建一个产品,但是当我尝试使用stripe.products.create()进行调用时,它会滞后,几秒钟后我的服务器因“JavaScript堆内存不足”而崩溃。

我是这样做的:

import stripePackage from 'stripe'
const stripe = stripePackage(config.stripe)

// after product is found in mongoose
stripe.products.create({
    id: product.sku,
    name: product.title,
    type: 'good',
    description: product.description,
    active: product.isAvailable,
    images: product.images,
    package_dimensions: {
        weight: product.shipping.weight * 16,
        length: product.shipping.dimension.length,
        width: product.shipping.dimension.width,
        height: product.shipping.dimension.height
    },
    shippable: true
}).then(stripeProduct => {
    console.log(stripeProduct.id);
    res.json(stripeProduct)
}).catch(err => {
    if (err) {
        console.log(err);
    }
})

CORS设置

app.use((req, res, next)=> {
  res.header("Access-Control-Allow-Origin", "*")
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, token, auth")
  res.header("Access-Control-Expose-Headers", "token")
  res.header("Access-Control-Allow-Methods", "POST,GET,PUT,DELETE,OPTIONS")
  next()
})

以下是express.js的崩溃报告:

<--- Last few GCs --->

[87147:0x102801e00]    61928 ms: Mark-sweep 1416.8 (1462.3) -> 1416.7 (1446.3) MB, 9502.3 / 0.0 ms  (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 9502 ms) last resort
[87147:0x102801e00]    72192 ms: Mark-sweep 1416.7 (1446.3) -> 1416.7 (1446.3) MB, 10263.3 / 0.0 ms  last resort


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x3ca24589cef1 <JSObject>
    1: encode(aka encode) [/Users/thousight/Projects/Project/node_modules/qs/lib/utils.js:~118] [pc=0x163bec732a95](this=0x3ca245882241 <undefined>,str=0x3ca2458822c1 <true>)
    2: arguments adaptor frame: 2->1
    3: stringify(aka stringify) [/Users/thousight/Projects/Project/node_modules/qs/lib/stringify.js:~32] [pc=0x163bec733b44](this=0x3ca245882241 <undefined>,object=0x3ca24588...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [/usr/local/bin/node]
2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
4: v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
5: v8::internal::LoadIC::LoadFullChain(v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>, v8::internal::Handle<v8::internal::Smi>) [/usr/local/bin/node]
6: v8::internal::LoadIC::UpdateCaches(v8::internal::LookupIterator*) [/usr/local/bin/node]
7: v8::internal::LoadIC::Load(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>) [/usr/local/bin/node]
8: v8::internal::Runtime_LoadIC_Miss(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
9: 0x163bec5840dd
10: 0x163bec732a95

它有什么问题吗?导致服务器崩溃的因素是什么?感谢

节点:v8.4.0 Stripe-Node:v5.8.0

1 个答案:

答案 0 :(得分:0)

如果您console.log传递给stripe.products.create()的对象,您会看到什么?有什么不寻常的事吗?你确定这是崩溃的地方吗?

编辑:更具体地说,这会带来什么回报?

console.log({
  id: product.sku,
  name: product.title,
  type: 'good',
  description: product.description,
  active: product.isAvailable,
  images: product.images,
  package_dimensions: {
    weight: product.shipping.weight * 16,
    length: product.shipping.dimension.length,
    width: product.shipping.dimension.width,
    height: product.shipping.dimension.height
  },
  shippable: true
});