RangeError:超出最大调用堆栈大小
Posted
技术标签:
【中文标题】RangeError:超出最大调用堆栈大小【英文标题】:RangeError: Maximum call stack size exceeded 【发布时间】:2016-04-02 16:05:58 【问题描述】:所以这里有一个使用 webtorrent 的简单函数:
addTorrent (opts)
return new Promise((resolve, reject) =>
try
console.log('in try catch');
let torrent = wtClient.add(opts.source, (torrent) =>
console.log('client.add callback');
var nled = normalize(torrent);
console.log('normalized ', torrent.infoHash);
resolve(nled);
);
console.log('after add')
torrent.on('download', (chunkSize) =>
console.log(chunkSize);
this.emit('torrent:' + torrent.infoHash + ':download', chunkSize);
);
console.log('after on');
catch(err)
console.log(pe.render(err));
process.exit(1);
reject(err);
);
并称它为:
var MAGNET_URI = 'magnet:?xt=urn:btih:09e37f73e51f403bb543517f0d0a2e1283d61eb0&dn=archlinux-2015.12.01-dual.iso&tr=udp://tracker.archlinux.org:6969&tr=http://tracker.archlinux.org:6969/announce';
socketClient.connect().then(() =>
console.log('Connected to webtorrent');
return socketClient.status();
).then((res) =>
console.log(res);
return socketClient.addTorrent(source: MAGNET_URI);
).then((data) =>
console.log('Added torrent:', data);
).catch((err) =>
console.log(err);
);
这是输出:
root@ubuntu-512mb-lon1-01:~/pTorrent# DEBUG=webtorrent,ut_metadata,dht,tracker,ut_pex npm start
> pTorrent@0.0.2 start /root/pTorrent
> node server.js --env=dev
webtorrent new webtorrent (peerId 2d5757303036332d323330643939666634313638, nodeId c59e8b616c66cf97437fd69f4ae037d00709b83b) +0ms
Listening at localhost:8080
Opening your system browser...
Client connected...
WEBPACK STUFF
Client connected...
in try catch
webtorrent add +42s
after add
after on
client.add callback
normalized 09e37f73e51f403bb543517f0d0a2e1283d61eb0
error occured for addTorrent
RangeError: Maximum call stack size exceeded
- Torrent.hasOwnProperty
- index.js:47 _hasBinary
[pTorrent]/[has-binary-data]/index.js:47:17
- index.js:37 _hasBinary
[pTorrent]/[has-binary-data]/index.js:37:15
- index.js:47 _hasBinary
[pTorrent]/[has-binary-data]/index.js:47:40
- index.js:47 _hasBinary
[pTorrent]/[has-binary-data]/index.js:47:40
- index.js:37 _hasBinary
[pTorrent]/[has-binary-data]/index.js:37:15
- index.js:47 _hasBinary
[pTorrent]/[has-binary-data]/index.js:47:40
- index.js:47 _hasBinary
[pTorrent]/[has-binary-data]/index.js:47:40
- index.js:37 _hasBinary
[pTorrent]/[has-binary-data]/index.js:37:15
- index.js:47 _hasBinary
[pTorrent]/[has-binary-data]/index.js:47:40
16384
16384
16384
16384
然后16384
会重复,直到内存耗尽。
编辑:经过一番研究,事实证明 16384 是每个 x 以非常高的速率接收的字节(因为我在 VPS 上)。我的 torrent 将在几秒钟内成功下载(在 /tmp/webtorrent/ 中找到它:D)
但这并不能解决由resolve();
行引起的 RangeError
【问题讨论】:
【参考方案1】:经过一番研究,事实证明 16384 是每 x 以非常高的速率接收的字节(因为我在 VPS 上)。我的 torrent 将在几秒钟内成功下载(在 /tmp/webtorrent/
中找到它:D)
RangeError 是由我的 normalize 函数引起的,它会留下对象并使其太大。
【讨论】:
以上是关于RangeError:超出最大调用堆栈大小的主要内容,如果未能解决你的问题,请参考以下文章
猫鼬:UnhandledPromiseRejectionWarning:RangeError:超出最大调用堆栈大小
Node.js + mongoose [RangeError: 超出最大调用堆栈大小]