【发布时间】:2016-02-14 04:01:25
【问题描述】:
我的 nodeJS 代码遇到了非常奇怪的问题。代码基本上是将 JSON 对象序列化为相对较大但不是非常大的文件 - ~150mb。问题是,当我尝试加载此文件时,会发生真正不确定的事情:
lapsio@linux-qzuq /d/g/GreenStorage> node
> k1=fs.readFileSync('../etc/md5index/green-Documents.extindex');0
0
> k1.length
157839101
> k2=fs.readFileSync('../etc/md5index/green-Documents.extindex');0
0
> k2.lengFATAL ERROR: invalid array length Allocation failed - process out of memory
fish: “node” terminated by signal SIGABRT (Abort)
第二次尝试
> k1=fs.readFileSync('../etc/md5index/green-Documents.extindex');0
0
> k2=fs.readFileSync('../etc/md5index/green-Documents.extindex');0
0
> k1.length
157839101
> k2.length
157839101
> k1==k2
false
从响应时间来看,这一步ofc文件已经缓存在RAM中了,所以不是存储问题。 我的实际应用:
try{
var ind = JSON.parse(args.legacyconvert?bfile:content),
ostr = String(args.legacyconvert?bfile:content),
str = JSON.stringify(ind,null,2);
for (var i = 0, l = str.length ; i < l ; i++)
if (str[i]!=ostr[i]){
console.error('Soft bug occured - it\'s serious bug and probably classifies as node bug or linux memcache bug. Should be reported');
throw ('Original string and reparsed don\'t match at '+i+' byte - system string conversion malfunction - abtorting')
}
return ind;
} catch (e) {
console.error('Could not read index - aborting',p,e);
process.exit(11);
}
结果:
lapsio@linux-qzuq /d/g/G/D/c/fsmonitor> sudo ./reload.js -e ../../../../etc/md5index/*.extindex
Reading index... ( ../../../../etc/md5index/green-Documents.extindex )
Soft bug occured - it's serious bug and probably classifies as node bug or linux memcache bug. Should be reported
Could not read index - aborting ../../../../etc/md5index/green-Documents.extindex Original string and reparsed don't match at 116655242 byte - system string conversion malfunction - abtorting
lapsio@linux-qzuq /d/g/G/D/c/fsmonitor> sudo ./reload.js -e ../../../../etc/md5index/*.extindex
Reading index... ( ../../../../etc/md5index/green-Documents.extindex )
Soft bug occured - it's serious bug and probably classifies as node bug or linux memcache bug. Should be reported
Could not read index - aborting ../../../../etc/md5index/green-Documents.extindex Original string and reparsed don't match at 39584906 byte - system string conversion malfunction - abtorting
它每次都返回随机字节不匹配。保存后文件损坏的可能性也有 50%。有时它甚至无法正确解析,因为它发现了一些奇怪的非 ASCII 字符,例如 [SyntaxError: Unexpected token 䀠]。它是来自 OpenSUSE 存储库的节点。我试过很多机器。重现此错误相对较难,因为它非常随机发生,但一旦第一次出现,它或多或少都会出现,直到重新启动。
lapsio@linux-qzuq /d/g/GreenStorage> node -v
v0.12.7
PC 有 16 GB 内存,而节点甚至没有达到 10%,所以我确信这不是内存不足的问题。而且这似乎不是文件系统相关的问题,因为 md5sum 和其他哈希生成器总是返回有效的校验和。只有节点失败。我不知道该怎么想。它真的被归类为错误吗?
【问题讨论】:
-
我无法确认这两个事件之间的直接关联,但我认为允许节点使用更多内存有助于解决这个问题 (
node --max_old_space_size=4096 ./file.js)
标签: node.js