Skip to content

Commit 37a2496

Browse files
Rachel Heatonjchampio
andauthored
Handle return events for poll() (#836)
On MacOS, there was a situation where poll() had POLLHUP in revents, which was not being handled by WaitForEvent. This caused poll to continuously run, taking CPU time (up to 100%). In spite of requesting POLLERR | POLLIN or POLLERR | POLLOUT, poll will also potentially return POLLHUP and POLLNVAL. [From the opengroup poll spec:](https://pubs.opengroup.org/onlinepubs/9699919799/functions/poll.html) "In addition, poll() shall set the POLLHUP, POLLERR, and POLLNVAL flag in revents if the condition is true, even if the application did not set the corresponding bit in events." We've removed the request for POLLERR from the file descriptor as it is unnecessary and misleading. This fix addresses the CPU usage on MacOS 11.6 when running a monitor that cannot connect to its nodes. Co-authored-by: Jacob Champion <pchampion@vmware.com>
1 parent fc92546 commit 37a2496

1 file changed

Lines changed: 3 additions & 4 deletions

File tree

src/monitor/health_check_worker.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,11 @@ WaitForEvent(List *healthCheckList)
748748

749749
if (healthCheck->pollingStatus == PGRES_POLLING_READING)
750750
{
751-
pollEventMask = POLLERR | POLLIN;
751+
pollEventMask = POLLIN;
752752
}
753753
else if (healthCheck->pollingStatus == PGRES_POLLING_WRITING)
754754
{
755-
pollEventMask = POLLERR | POLLOUT;
755+
pollEventMask = POLLOUT;
756756
}
757757

758758
pollFileDescriptor->fd = PQsocket(connection);
@@ -786,8 +786,7 @@ WaitForEvent(List *healthCheckList)
786786
HealthCheck *healthCheck = (HealthCheck *) lfirst(healthCheckCell);
787787
struct pollfd *pollFileDescriptor = &pollFDs[healthCheckIndex];
788788

789-
healthCheck->readyToPoll = pollFileDescriptor->revents &
790-
pollFileDescriptor->events;
789+
healthCheck->readyToPoll = pollFileDescriptor->revents != 0;
791790

792791
healthCheckIndex++;
793792
}

0 commit comments

Comments
 (0)