V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
xnile
V2EX  ›  Node.js

求解一个 nodejs 内存泄露问题

  •  
  •   xnile · Nov 27, 2018 · 3540 views
    This topic created in 2720 days ago, the information mentioned may be changed or developed.

    tail () { const ts = this.lastTs const nss = this.defs.map(def => def.ns) const filters = { ns: { $in: nss }, ts: { $gt: Timestamp.fromNumber(ts) } } const curOpts = { tailable: true, awaitdata: true, numberOfRetries: 60 * 60 * 24, // Number.MAX_VALUE, tailableRetryInterval: 1000 }

    util.log(`Begin to watch... (from ${ts})`)
    return new Promise((resolve, reject) =>
      mongodb.connect(this.url2).then(db => {
        this.db = db
        const stream = db.collection('oplog.rs').find(filters, curOpts).stream()
        stream
          .on('data', log => {
            if (log.op === 'n' || log.ts.toNumber() === ts) return
            this.process(log)
          })
          .on('close', () => {
            util.log('Stream closed....')
            this.db = null
            db.close()
            resolve()
          })
          .on('error', err => {
            this.db = null
            db.close()
            reject(err)
          })
      }))
    

    }

    目的是读取 monogodb 的 oplog 将数据同步到 mysql 里边

    2 replies    2018-11-28 09:06:07 +08:00
    TomVista
        1
    TomVista  
       Nov 27, 2018 via iPhone
    return 函数对象形成的闭包导致,对象用完指定为 null,应该是这个理
    xnile
        2
    xnile  
    OP
       Nov 28, 2018 via iPhone
    @TomVista 感谢指点
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3138 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 11:17 · PVG 19:17 · LAX 04:17 · JFK 07:17
    ♥ Do have faith in what you're doing.