swiftlang / swiftlang/swift-corelibs-libdispatch

[SR-7316] libdispatch: DISPATCH_SOURCE_TYPE_DATA_* does not work with the epoll backend (linux)

Open
#658 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug libdispatch
Dominant language
C
Stars
2.6k
Forks
496
Avg merge
2d 6h
Merged PRs (30d)
3

Description

Previous ID SR-7316
Radar None
Original Reporter moshe (JIRA User)
Type Bug
Environment

Fedora 27 with Clang 5.0.1

Additional Detail from JIRA
Votes 0
Component/s libdispatch
Labels Bug
Assignee None
Priority Medium

md5: fe128027ec00cf3b8931697f12b72939

Issue Description:

The following C program will crash for me:

#include <dispatch/dispatch.h>

int main(int argc, char **argv, char **envp) {
{{ dispatch_queue_t main_queue = dispatch_get_main_queue();}}
{{ dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_DATA_ADD, 0, 0, main_queue);}}
{{ dispatch_resume(source);}}
{{ dispatch_main();}}
};

The issue is within _dispatch_muxnote_create of the epoll backend, this code hits the DISPATCH_INTERNAL_CRASH on line src/event/event_epoll.c:200.

Adding a case for DISPATCH_EVFILT_CUSTOM_ADD in that switch statement solves the crash, but I don't actually know what it is supposed to do if I add it. Limited testing (with actual event handlers) did not uncover any obvious bugs for me with no code in the case.

Installing a kqueue/kevent compatibility library and changing the build to use the kevent backend also works on my linux installation. I guess the epoll backend should be fixed, but in addition, I would like to propose a build time option to switch the backend on linux systems that have kqueue/kevent.

(DISPATCH_SOURCE_TYPE_DATA_OR has the same issue.)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproducer and inspect _dispatch_muxnote_create in src/event/event_epoll.c, especially the DISPATCH_INTERNAL_CRASH at line 200 and the DISPATCH_EVFILT_CUSTOM_ADD switch case. Compare the epoll and kevent backends, then verify DISPATCH_SOURCE_TYPE_DATA_ADD and DISPATCH_SOURCE_TYPE_DATA_OR with actual event handlers. Done means these sources no longer crash on Linux with epoll.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, linux
Domain
backend, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.