sodazone / ocelloids-services

Ocelloids Service Layer
https://ocelloids.net
Apache License 2.0
9 stars 3 forks source link

Fix memory leak in long-running ApiRx subs #49

Closed XY-Wang closed 8 months ago

XY-Wang commented 8 months ago

ApiRx subscriptions are memoized using an in-memory object as cache that is only cleaned up on unsubscribe. For our case this causes the server to run out of memory after running for some hours.

https://github.com/polkadot-js/common/blob/db25938ad7867d98abad0cdb457b6aabb4bec38b/packages/util/src/memoize.ts#L22

XY-Wang commented 8 months ago

Additional note: same memoize is used to wrap all RPC interface methods and internal getBlockHash and getBlockRegistry in the Api. So even without long-running subscriptions the API could run out of memory if makes too many requests.