Issue 19208: Avoid double close of file-descriptors (poll)

After closing a file descriptor honor the "closed" flag to avoid
re-closing it in post-fork processing.

File descriptors must be closed during an orphan operation, because
the closing of the file-descriptor is necessary for the correct function
of code that is polling on the descriptor.  Thus even if there are active
references, the close() call is necessary.  But this means that post-fork
code may close the file-descriptor, since it is only unregistered from
post-fork after the ref-count reaches 0.  All of this can be handled by
ensuring that the post-fork code honors the "close" flag.
pull/20888/head
Michal Ostrowski 6 years ago committed by Lidi Zheng
parent bd0d9bb63c
commit f16fcaacb4
  1. 4
      src/core/lib/iomgr/ev_poll_posix.cc

@ -1379,7 +1379,9 @@ static void reset_event_manager_on_fork() {
gpr_mu_lock(&fork_fd_list_mu);
while (fork_fd_list_head != nullptr) {
if (fork_fd_list_head->fd != nullptr) {
close(fork_fd_list_head->fd->fd);
if (!fork_fd_list_head->fd->closed) {
close(fork_fd_list_head->fd->fd);
}
fork_fd_list_head->fd->fd = -1;
} else {
close(fork_fd_list_head->cached_wakeup_fd->fd.read_fd);

Loading…
Cancel
Save