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

Always report timers/events when worker unparked #4227

Merged
merged 1 commit into from
Jan 6, 2025

Conversation

armanbilge
Copy link
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
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 🤷

Copy link
Member

@djspiewak djspiewak left a comment

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
29 of 33 checks passed
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