Thread safety guidance for concurrent server-side usage (Node.js/Next.js SSR)

While using @hiveio/wax in denser, under concurrent load, we encounter WASM memory corruption:

  WaxError: Non-typed Error during Wasm call: RuntimeError: memory access out of bounds
      at nn.isValidAccountName

There's a singleton pattern for the chain instance:

// hive-chain-service.ts
export class HiveChainService {
  static hiveChain: HiveChain;

  async getHiveChain(): Promise<HiveChain> {
    if (!HiveChainService.hiveChain) {
      HiveChainService.hiveChain = await createHiveChain(options);
    }
    return HiveChainService.hiveChain;
  }
}

Multiple Server Components call chain.isValidAccountName() concurrently during SSR, causing the memory error.

Questions

  1. How to properly use wax to be thread-safe for concurrent access in Node.js?
  2. What is the recommended pattern for server-side usage with concurrent requests? - Should we create separate chain instances per request? - Should we serialize calls with a mutex? - Is there a built-in mechanism we're missing?
  3. Are certain methods (like isValidAccountName) safe for concurrent use while others aren't?