Skip to content
Snippets Groups Projects
Commit b3320fc7 authored by Craig Tiller's avatar Craig Tiller
Browse files

Fix race in poll() based pollset

It was possible for entries in watchers[] to be deleted by another thread before we called begin_poll.

I'd like to do something nicer than this eventually... but that'll be easier once we've got the polling loop cleaned up (which is currently WIP)
parent a8712e01
No related branches found
No related tags found
No related merge requests found
...@@ -122,6 +122,7 @@ static void multipoll_with_poll_pollset_maybe_work_and_unlock( ...@@ -122,6 +122,7 @@ static void multipoll_with_poll_pollset_maybe_work_and_unlock(
} else { } else {
h->fds[fd_count++] = h->fds[i]; h->fds[fd_count++] = h->fds[i];
watchers[pfd_count].fd = h->fds[i]; watchers[pfd_count].fd = h->fds[i];
GRPC_FD_REF(watchers[pfd_count].fd, "multipoller_start");
pfds[pfd_count].fd = h->fds[i]->fd; pfds[pfd_count].fd = h->fds[i]->fd;
pfds[pfd_count].revents = 0; pfds[pfd_count].revents = 0;
pfd_count++; pfd_count++;
...@@ -135,8 +136,10 @@ static void multipoll_with_poll_pollset_maybe_work_and_unlock( ...@@ -135,8 +136,10 @@ static void multipoll_with_poll_pollset_maybe_work_and_unlock(
gpr_mu_unlock(&pollset->mu); gpr_mu_unlock(&pollset->mu);
for (i = 2; i < pfd_count; i++) { for (i = 2; i < pfd_count; i++) {
pfds[i].events = (short)grpc_fd_begin_poll(watchers[i].fd, pollset, worker, grpc_fd *fd = watchers[i].fd;
pfds[i].events = (short)grpc_fd_begin_poll(fd, pollset, worker,
POLLIN, POLLOUT, &watchers[i]); POLLIN, POLLOUT, &watchers[i]);
GRPC_FD_UNREF(fd, "multipoller_start");
} }
/* TODO(vpai): Consider first doing a 0 timeout poll here to avoid /* TODO(vpai): Consider first doing a 0 timeout poll here to avoid
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment