Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wallet out-of-memory crash on synchronization #929

Open
braydonf opened this issue Jan 16, 2020 · 2 comments
Open

Wallet out-of-memory crash on synchronization #929

braydonf opened this issue Jan 16, 2020 · 2 comments
Labels
bug Unexpected or incorrect behavior memory Memory issues wallet Wallet related
Milestone

Comments

@braydonf
Copy link
Contributor

braydonf commented Jan 16, 2020

Summary

Under certain conditions a wallet will run out of memory when syncing.

Reproduce

It's somewhat difficult to reproduce this case. For the process to be out-of-memory, the rate that the wallet processes and adds blocks needs to be slower than the rate that blocks are added to the chain. This set of conditions are likely more relevant to an SPV node and wallet, however it could apply in any case. What happens is that there are many transactions and blocks that pile up in memory in a queue. That queue is the jobs field of the txLock from bmutex in the wdb database .

@braydonf braydonf added wallet Wallet related memory Memory issues labels Jan 16, 2020
@braydonf braydonf added this to the v2.0.0 milestone Jan 16, 2020
@braydonf braydonf changed the title Wallet out-of-memory on syncronization Wallet out-of-memory on synchronization Jan 16, 2020
@braydonf braydonf added the bug Unexpected or incorrect behavior label Jan 16, 2020
@braydonf
Copy link
Contributor Author

braydonf commented Jan 17, 2020

A temporary solution:

Use emitAsync and an async function for the wallet adding blocks, similar to how chain will wait for the indexers. This will only work when the wallet is in the same process as a plugin, and not when the wallet is running as a separate process. This can work as a temporary solution for the SPV node.

diff --git a/lib/wallet/nodeclient.js b/lib/wallet/nodeclient.js
index 272e45094..89d9818f4 100644
--- a/lib/wallet/nodeclient.js
+++ b/lib/wallet/nodeclient.js
@@ -36,18 +36,18 @@ class NodeClient extends AsyncEmitter {
    */
 
   init() {
-    this.node.on('connect', (entry, block) => {
+    this.node.chain.on('connect', async (entry, block) => {
       if (!this.opened)
         return;
 
-      this.emit('block connect', entry, block.txs);
+      await this.emitAsync('block connect', entry, block.txs);
     });
 
     this.node.on('tx', (tx) => {

@braydonf braydonf changed the title Wallet out-of-memory on synchronization Wallet out-of-memory crash on synchronization Jan 23, 2020
@braydonf
Copy link
Contributor Author

This is addressed in part by #932. For the wallet as a process, there will need to be another fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Unexpected or incorrect behavior memory Memory issues wallet Wallet related
Projects
None yet
Development

No branches or pull requests

1 participant