Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(iroh-relay): do not use spawn_blocking in stun handler (#2924)
## Description This resulted in memory accumulation , due to blocking threads not getting shutdown, once started. According to the docs from tokio, there is no way to cleanup these tasks/threads, once they have been started. From the docs: https://docs.rs/tokio/latest/tokio/task/fn.spawn_blocking.html > Be aware that tasks spawned using spawn_blocking cannot be aborted because they are not async. If you call [abort](https://docs.rs/tokio/latest/tokio/task/struct.JoinHandle.html#method.abort) on a spawn_blocking task, then this will not have any effect, and the task will continue running normally. The exception is if the task has not started running yet; in that case, calling abort may prevent the task from starting. > > When you shut down the executor, it will wait indefinitely for all blocking operations to finish. You can use [shutdown_timeout](https://docs.rs/tokio/latest/tokio/runtime/struct.Runtime.html#method.shutdown_timeout) to stop waiting for them after a certain timeout. Be aware that this will still not cancel the tasks — they are simply allowed to keep running after the method returns. It is possible for a blocking task to be cancelled if it has not yet started running, but this is not guaranteed. The referred to limit is `512` by default, meaning with the default thread stack size of `2MiB`, we are looking at `1GiB` of memory, simply for keeping around these threads. Looking at https://docs.rs/tokio/latest/tokio/runtime/struct.Builder.html#method.thread_keep_alive these threads should get cleaned up after `10s`, but this does not seem to happen. So there seems to be some unintended lingering to happen, in either case. ## Breaking Changes None ## Notes & open questions This is unfortuante, but the parsing of stun packets should be fast enough. ## Change checklist - [x] Self-review. - [x] Documentation updates following the [style guide](https://rust-lang.github.io/rfcs/1574-more-api-documentation-conventions.html#appendix-a-full-conventions-text), if relevant. - [x] Tests if relevant. - [x] All breaking changes documented.
- Loading branch information