fix(pnet): bound xsalsa20 wasm memory per message and per connection - #3585
Conversation
# Conflicts: # packages/pnet/src/crypto.ts # packages/pnet/test/index.spec.ts
Each cipher holds a slot in a process-global wasm pool that is only returned by finalize, which pnet never called, so every connection leaked one per direction until the pool was exhausted and all pnet traffic began to fail.
|
Added a few things to this branch. pnet has never called Opening and closing 500 connections now leaves the pool where it started. Before, it grew every time and never came back down. This is on your PR rather than its own because it doesn't work without your chunking. Growing the wasm memory breaks I also reworked the tests. The large message test only checked how many bytes arrived, which passes even with encryption turned off, so it now checks the bytes themselves. I renamed |
Sending large messages through connections protected by pnet throws:
This PR windows the xsalsa xor so it never grows and exceeds its memory limits. There is also a test added that demonstrates this fix.