[Bug] Maximum call stack size exceeded
Closed this issue · 1 comments
Describe the bug
A caver instance is crashed if the reproduce code snippet is run.
How to reproduce
Run the below.
let url = ...
let nAccounts = 100000;
const caver = new Caver(url); // (1)
for (let i=0; i<nAccounts; i++) {
//const caver = new Caver(url); // (2)
let randomHex = '0x' + genRanHex(64);
let sender = caver.klay.accounts.wallet.add(randomHex).address;
console.log("created account", i+1)
}
No error happens If you comment (1) and uncomment (2).
Expected behavior
Must not happen Maximum call stack size exceeded
.
Attachments
created account 1
...
...
...
created account 7846
Wallet.prototype._findSafeIndex = function(pointer) {
^
RangeError: Maximum call stack size exceeded
at Wallet._findSafeIndex (/home/hyunsoo/servicechain-value-transfer-examples/node_modules/caver-js/packages/caver-klay/caver-klay-accounts/src/index.js:1705:43)
at Wallet._findSafeIndex (/home/hyunsoo/servicechain-value-transfer-examples/node_modules/caver-js/packages/caver-klay/caver-klay-accounts/src/index.js:1708:21)
at Wallet._findSafeIndex (/home/hyunsoo/servicechain-value-transfer-examples/node_modules/caver-js/packages/caver-klay/caver-klay-accounts/src/index.js:1708:21)
at Wallet._findSafeIndex (/home/hyunsoo/servicechain-value-transfer-examples/node_modules/caver-js/packages/caver-klay/caver-klay-accounts/src/index.js:1708:21)
at Wallet._findSafeIndex (/home/hyunsoo/servicechain-value-transfer-examples/node_modules/caver-js/packages/caver-klay/caver-klay-accounts/src/index.js:1708:21)
at Wallet._findSafeIndex (/home/hyunsoo/servicechain-value-transfer-examples/node_modules/caver-js/packages/caver-klay/caver-klay-accounts/src/index.js:1708:21)
at Wallet._findSafeIndex (/home/hyunsoo/servicechain-value-transfer-examples/node_modules/caver-js/packages/caver-klay/caver-klay-accounts/src/index.js:1708:21)
at Wallet._findSafeIndex (/home/hyunsoo/servicechain-value-transfer-examples/node_modules/caver-js/packages/caver-klay/caver-klay-accounts/src/index.js:1708:21)
at Wallet._findSafeIndex (/home/hyunsoo/servicechain-value-transfer-examples/node_modules/caver-js/packages/caver-klay/caver-klay-accounts/src/index.js:1708:21)
at Wallet._findSafeIndex (/home/hyunsoo/servicechain-value-transfer-examples/node_modules/caver-js/packages/caver-klay/caver-klay-accounts/src/index.js:1708:21)
Environment (please complete the following information)
^caver-1.6.8
Additional context
I didn't take a look at the implementation for now. Maybe, the caver instance seems to have API call's management stack and seems not cleared them correctly. You don't need to fully trust my comment because it's an assumption on the black-box (I don't have the Caver's implementation background)
Hi, thank you for reporting an issue.
I checked the logic, and i figured out caver.klay.accounts.wallet
which is supported before common architecture of Klaytn SDK, assign an index to the account object when add to wallet.
But in order to fill the account without an index empty in the middle of the wallet, starting from 0, an empty index in the wallet is searched.
Starting from 0, if there is an account account in the index, increment the index and call it using a recursive function.
That means, if 10,000 accounts are existed in wallet, then _findSafeIndex
will be called recursively 10,000 times.
Because of this, now caver.klay.accounts.wallet
cannot handle too many account instances like what you tested above.
I can fix this issue, but If you urgent to use many accounts, then you can use caver.wallet.add
and caver.wallet.keyring.generate()
supported in common architecture feature without any call stack errors.
#652
Thank you for reporting again.