Skip to content

Fix improper double-fire of signal sources on Linux #279

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

Merged
merged 1 commit into from
Jul 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/event/event_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,12 +467,24 @@ _dispatch_event_merge_signal(dispatch_muxnote_t dmn)
{
dispatch_unote_linkage_t dul, dul_next;
struct signalfd_siginfo si;

dispatch_assume(read(dmn->dmn_fd, &si, sizeof(si)) == sizeof(si));

TAILQ_FOREACH_SAFE(dul, &dmn->dmn_readers_head, du_link, dul_next) {
dispatch_unote_t du = _dispatch_unote_linkage_get_unote(dul);
dux_merge_evt(du._du, EV_ADD|EV_ENABLE|EV_CLEAR, 1, 0, 0);
ssize_t rc;

// Linux has the weirdest semantics around signals: if it finds a thread
// that has not masked a process wide-signal, it may deliver it to this
// thread, meaning that the signalfd may have been made readable, but the
// signal consumed through the legacy delivery mechanism.
//
// Because of this we can get a misfire of the signalfd yielding EAGAIN the
// first time around. The _dispatch_muxnote_signal_block_and_raise() hack
// will kick in, the thread with the wrong mask will be fixed up, and the
// signal delivered to us again properly.
if ((rc = read(dmn->dmn_fd, &si, sizeof(si))) == sizeof(si)) {
TAILQ_FOREACH_SAFE(dul, &dmn->dmn_readers_head, du_link, dul_next) {
dispatch_unote_t du = _dispatch_unote_linkage_get_unote(dul);
dux_merge_evt(du._du, EV_ADD|EV_ENABLE|EV_CLEAR, 1, 0, 0);
}
} else {
dispatch_assume(rc == -1 && errno == EAGAIN);
}
}

Expand Down