hapostgres / pg_auto_failover

Postgres extension and service for automated failover and high-availability
Other
1.09k stars 114 forks source link

Handle return events for poll() #836

Closed rheaton closed 2 years ago

rheaton commented 2 years ago

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: "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