element-hq / hydrogen-web

Lightweight matrix client with legacy and mobile browser support
Apache License 2.0
650 stars 127 forks source link

Olm encryption for more than 44 devices fails because libolm runs out of memory #150

Closed bwindels closed 4 years ago

bwindels commented 4 years ago

After the first sync, we send out any pending room key shares in the operations store. This seems to fail without exception (trying with 3 operations in my store now) with the following olm error:

Cannot enlarge memory arrays. Either (1) compile with  -s TOTAL_MEMORY=X  with X higher than the current value 262144, (2) compile with  -s ALLOW_MEMORY_GROWTH=1  which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with  -s ABORTING_MALLOC=0 

It is surprising that it would already have hit the memory limit right after loading the session, from a cold session load.

This is hydrogen 0.1.10 on latest Chrome.

bwindels commented 4 years ago

I think this is because my test account has 53 e2ee devices and while encrypting a message, we keep hold of all outbound olm sessions. It fails to allocate the 45th olm outbound session. One outbound session needs 3320 bytes, so 44x3320=146080 bytes seems to make us run out of memory.

bwindels commented 4 years ago

We should either increase the memory limit, or not run encryption in parallel anymore.

bwindels commented 4 years ago

Or likely just decrease MAX_BATCH_SIZE in olm/Encryption.js...