Skip to content

Always report timers/events when worker unparked#4227

Merged
djspiewak merged 1 commit into
typelevel:series/3.6.xfrom
armanbilge:issue/4225
Jan 6, 2025
Merged

Always report timers/events when worker unparked#4227
djspiewak merged 1 commit into
typelevel:series/3.6.xfrom
armanbilge:issue/4225

Conversation

@armanbilge

Copy link
Copy Markdown
Member

Fixes #4225.

A parked worker may wake up for various reasons:

  1. expired timer or polling event
  2. external interruption / unparking, due to availability of external work
  3. spurious wakeup

Due to race conditions, a worker may actually wake up for multiple reasons simultaneously. Thus, it should always check first if there are expired timers or polling events, so it can transition to handling those, before considering other cases.


In #4225, we were able to detect this bug because the WSTP had only one worker.

  1. the I/O event completes and the callback reschedules the associated fiber
  2. while rescheduling the fiber, the worker notifies the pool that there is work available to steal
  3. the pool unparks the one-and-only worker (another thing we should consider tweaking: don't unpark thyself)
  4. the worker believes it was unparked due to external work (there is none) and meanwhile doesn't transition to handling its actual local work
  5. the worker goes back to sleep until the next timer fires, at which point it properly transitions to handling local work

@armanbilge armanbilge added this to the v3.6.0 milestone Jan 6, 2025
@armanbilge armanbilge linked an issue Jan 6, 2025 that may be closed by this pull request
@armanbilge

Copy link
Copy Markdown
Member Author

There's possibly a bigger discussion here, which is whether the fact that polling systems schedule tasks on a worker's local queue while the worker is parked violates some invariant of our runtime 🤷

@djspiewak djspiewak left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice catch!

@djspiewak
djspiewak merged commit e1da97e into typelevel:series/3.6.x Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

I/O polling hangs when computeWorkerThreadCount = 1

2 participants