Skip to content

Do not wait on freed fiber - #1773

Merged
bakpakin merged 1 commit into
janet-lang:masterfrom
Samuel-Martineau:do-not-wait-on-freed-fiber
Jul 1, 2026
Merged

Do not wait on freed fiber#1773
bakpakin merged 1 commit into
janet-lang:masterfrom
Samuel-Martineau:do-not-wait-on-freed-fiber

Conversation

@Samuel-Martineau

@Samuel-Martineau Samuel-Martineau commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Possible fix for #1772.

@bakpakin

Copy link
Copy Markdown
Member

This looks at first glance correct, but the fact that this was missed tells me we should simplify the refcounting logic a bit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a scheduler/event-loop liveness bug where a fiber that is manually suspended (via yield, not IO) can be garbage collected while still contributing to the event loop’s reference count, preventing the program from exiting (issue #1772).

Changes:

  • Decrement the event loop listener/refcount when a GC-finalized fiber was previously marked as EV-suspended but has no ev_state.
  • Preserve existing cleanup behavior for fibers with ev_state (and Windows in-flight handling).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/core/gc.c
Comment on lines +339 to +340
} else if (f->gc.flags & JANET_FIBER_EV_FLAG_SUSPENDED) {
janet_ev_dec_refcount();
@Samuel-Martineau

Copy link
Copy Markdown
Contributor Author

That is my feeling too... Let's just say that I am not very confident that this is the only issue of this kind

@bakpakin
bakpakin marked this pull request as ready for review June 30, 2026 00:55
@bakpakin
bakpakin merged commit c0b32d4 into janet-lang:master Jul 1, 2026
17 of 18 checks passed
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