Closed Naalunth closed 2 weeks ago
Wow, great find! I need to build a test for this and immediately fix it. (well you already did)
(I initially thought this was something I did with the introduction of ArrayPools for Storages)
I wanted to move away from the ArrayPoolstackalloc
arrays caused the JIT to stop inlining).
Thank you very much for this significant contribution! 💙
This minimal program on its own currently reproduces the bug fixed in this pull request every single time.
The problem was that
ArrayPool<T>.Rent
may return longer arrays than expected. Further down, the length of the arrays was used for logic, without clearing junk data that might have still been in there. In the program where I discovered the bug, this led to a Stream running millions of iterations on a single Entity, and executing the according side effects on every iteration.