Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

ysbaddaden
Copy link
Contributor

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

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 crystal-lang#14633
@ysbaddaden ysbaddaden added the kind:bug A bug in the code. Does not apply to documentation, specs, etc. label May 28, 2024
@ysbaddaden ysbaddaden self-assigned this May 28, 2024
@straight-shoota straight-shoota modified the milestones: 1.13.0, 1.12.2 May 28, 2024
@straight-shoota straight-shoota changed the title Fix: don't allocate on Fiber.unsafe_each and Thread.unsafe_each Fix: Don't allocate on Fiber.unsafe_each and Thread.unsafe_each May 28, 2024
@straight-shoota straight-shoota changed the title Fix: Don't allocate on Fiber.unsafe_each and Thread.unsafe_each Fix: Don't allocate in Fiber.unsafe_each and Thread.unsafe_each May 28, 2024
@Sija
Copy link
Contributor

Sija commented May 28, 2024

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

@ysbaddaden
Copy link
Contributor Author

@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
Copy link
Contributor

Sija commented May 28, 2024

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

@bcardiff
Copy link
Member

Darn, I hoped this would solve also bcardiff/crystal-fswatch#5 but it does not seem the case.

@straight-shoota straight-shoota merged commit db612c1 into crystal-lang:master May 29, 2024
61 checks passed
@ysbaddaden ysbaddaden deleted the fix/dont-lazily-initialize-thread-abnd-fiber-linked-list-on-iteration branch May 30, 2024 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:runtime
Projects
None yet
4 participants