threading icon indicating copy to clipboard operation
threading copied to clipboard

Flushing channels on destroy

Open darkestpigeon opened this issue 1 year ago • 1 comments

Right now when a channel with pending messages is destroyed, a memory leak can occur if the messages themselves have non-trivial destructors. This PR aims to fix this via receiving all the pending messages during channel destruction. Also adding tryRecv with Option[T} result instead of an out parameter and a boolean flag for convenience.

darkestpigeon avatar Oct 17 '24 12:10 darkestpigeon

Found some apparent problems with the compiler due to this change, distilled and reported them in nim-lang/Nim#24374 Here the =destroy, and hence tryRecv can be called with a wrong type during flushing, which can lead to a segfault or other nasty behaviour.

darkestpigeon avatar Oct 28 '24 13:10 darkestpigeon