Skip to content

Implement blocking support for epoll #3805

@tiif

Description

@tiif

In #3712, any epoll_wait call with non-zero timeout value is currently rejected using throw_unsup_formatbecause blocking for file descriptions is not supported yet. This is part of the work for tokio support in #602 .

Below are some very high-level and rough steps that would be needed to support blocking epoll:

  1. Refactor the main logic of epoll_wait into a function, as demonstrated in a1fc187. This can also be done together with the step below.
  2. Use this.block_thread in epoll_wait, and this.unblock_thread in check_and_update_readiness.
    2.1 To get this.unblock_threadto work, we might need to introduce some data structures to know which thread should we wake up when there is an epoll notification for a file description.

@oli-obk mentioned an interesting test case that might be a data race on file description level: one thread close epoll file descriptor while another thread is blocking on that epoll file descriptor.

Visualisation:

thread 1                                     |  thread 2
epoll_wait on epoll file descriptor 5 blocks |
                                             |  close(5)
                                             |
                                             
                                             
> What should happen here? Reject the close or terminate the blocking operation? 

It seems like closing a file descriptor while blocking on it is UB, related SO discussion:

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-filesArea: related to files, paths, sockets, file descriptors, or handlesA-shimsArea: This affects the external function shimsC-enhancementCategory: a PR with an enhancement or an issue tracking an accepted enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions