NodeJs,moch / chai在macOS上出现“Segmentation fault:11”失败

我正在运行mocha / chai(3.2.0 / 3.5.0)基于我的nodejs(6.10.2)基于应用程序的testing用例,在macOS 10.12.4,我运行到“分段错误:11”失败。

到目前为止我已经尝试过:

  • 擦除我的node_modules文件夹并做一个新的npm install
  • 检查过时的依赖关系并升级它们
  • 通过sudo port upgrade nodejs6升级nodejs版本(使用6.7.0)

对我来说失败的代码如下。

  chai.request(url) .post(`/api/filestore?token=${token}`) .timeout(20000) .attach('file', fs.readFileSync(filepath), filename) .field('name', data.name) .field('description', data.description) .field('keywords', data.keywords) .end(function(err, res) { if (err) { done(err); } res.should.have.status(200); res.should.be.json; res.body.should.have.property('name'); res.body.should.have.property('description'); res.body.should.have.property('categories'); res.body.keywords.should.be.a('array'); res.body.keywords.join(',').should.be.equal(data.keywords); done(); }); 

删除“附加”行时,分段错误消失:

 .attach('file', fs.readFileSync(filepath), filename) 

我已经单独尝试了fs.readFileSync(filepath) ,我没有遇到这个问题。

这在过去不是问题,最近才成为问题。 我想知道它是否与操作系统的升级是一致的,但我不能确定。 testing文件只有34K大小。

有没有人有什么build议?

编辑:在Ubuntutesting机上也出现分段错误。

柴代码似乎是一个“红鲱鱼”。 使用segfault-handler节点模块,我能够确定问题实际上是由正在testing的项目中的代码引起的(它在同一个进程中运行)。

在我的情况下,堆栈跟踪表明这个问题是由sqlite3代码中的东西造成的。 进一步的调查显示,这是因为没有处理通过Promise.mapSeries传递给Promise.mapSeries的函数的返回值,该Promise.mapSeries正在执行sqlite SQL操作。

注意我正在使用蓝鸟作为我的承诺。