[TS] Implement near-heap-limit termination by coolreader18 · Pull Request #4777 · clockworklabs/SpacetimeDB

Description of Changes

Uses Isolate::add_near_heap_limit_callback to prevent unbounded heap growth. Upon nearing the heap limit, we will now:

  1. Call Isolate::terminate_execution.
  2. Request that v8 double the heap limit.

Then, upon finishing a function call, we lower the heap limit back down.

This should hopefully fix the issue where v8 hits the heap limit and crashes the whole process.

Expected complexity level and risk

2

Testing

  • Manual testing with memory-leaky modules