Skip to content

Conversation

@viktorerlingsson
Copy link
Member

@viktorerlingsson viktorerlingsson commented Jan 12, 2026

Summary

This PR extracts the BoolChannel changes from #1549

Changes

  • Replace spawn(name: "BoolChannel#send_loop") with atomic state management using Atomic(Bool)
  • Introduce StateChannel class that extends Channel(Nil) with activate/deactivate methods
  • Use EndlessQueue to implement channels that signal state without blocking on send
  • Remove the send_loop fiber entirely, reducing fiber allocations by one per BoolChannel instance

Replace the spawned send_loop fiber with atomic operations and direct
channel state manipulation. This eliminates a fiber allocation that
could fail mid-constructor, which would leave orphaned fibers accessing
uninitialized instance variables and cause segfaults.

This change mitigates the issue in #1595 where BoolChannel.new could fail
after spawning deliver_loop but before initializing all BoolChannel fields.

Changes extracted from PR #1549.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@viktorerlingsson viktorerlingsson requested a review from a team as a code owner January 12, 2026 14:42
@viktorerlingsson viktorerlingsson changed the title BoolChannel: eliminate spawned fiber to mitigate segfault in #1595 BoolChannel: Donmtspawned fiber Jan 12, 2026
@viktorerlingsson viktorerlingsson changed the title BoolChannel: Donmtspawned fiber BoolChannel: Don't spawn fiber Jan 12, 2026
@viktorerlingsson viktorerlingsson merged commit 52b83d3 into main Jan 13, 2026
18 checks passed
@viktorerlingsson viktorerlingsson deleted the bool-channel-no-fiber branch January 13, 2026 08:51
viktorerlingsson added a commit that referenced this pull request Jan 13, 2026
This PR extracts the BoolChannel changes from #1549

- Eliminate the spawned fiber in `BoolChannel` constructor by replacing
it with atomic operations and direct channel state manipulation
- This mitigates the segfault issue in #1595 where `BoolChannel.new`
could fail after spawning a fiber but before initializing all instance
variables, leaving orphaned fibers that access uninitialized memory
- Also mitigates #1595 just by creating less fibers, resulting in fewer
memory maps

- Replace `spawn(name: "BoolChannel#send_loop")` with atomic state
management using `Atomic(Bool)`
- Introduce `StateChannel` class that extends `Channel(Nil)` with
`activate`/`deactivate` methods
- Use `EndlessQueue` to implement channels that signal state without
blocking on send
- Remove the `send_loop` fiber entirely, reducing fiber allocations by
one per BoolChannel instance

Co-authored-by: Carl Hörberg <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants