crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.21k stars 1.61k forks source link

Fix: Don't allocate in `Fiber.unsafe_each` and `Thread.unsafe_each` #14635

Closed ysbaddaden closed 1 month ago

ysbaddaden commented 1 month ago

These methods are called during GC collections, which may happen before the Thread::LinkedList objects are created, leading to an infinite loop of malloc -> collect -> malloc -> collect -> ...

Kudos to @BlobCodes for identifying the issue!

fixes #14633

Sija commented 1 month ago

I'd suggest adding a note at the callsites re: the reasoning behind this.

ysbaddaden commented 1 month ago

@Sija I went to write a note, but then it occurred to me that if the object doesn't exist then there's nothing to iterate in the first place.

Sija commented 1 month ago

True, yet the future me would like to know that these methods shouldn't allocate anything.

bcardiff commented 1 month ago

Darn, I hoped this would solve also https://github.com/bcardiff/crystal-fswatch/issues/5 but it does not seem the case.