{"id":9398,"date":"2016-10-11T13:26:46","date_gmt":"2016-10-11T11:26:46","guid":{"rendered":"https:\/\/daniel.haxx.se\/blog\/?p=9398"},"modified":"2024-09-30T23:33:50","modified_gmt":"2024-09-30T21:33:50","slug":"poll-on-mac-10-12-is-broken","status":"publish","type":"post","link":"https:\/\/daniel.haxx.se\/blog\/2016\/10\/11\/poll-on-mac-10-12-is-broken\/","title":{"rendered":"poll on mac 10.12 is broken"},"content":{"rendered":"\n<p>When Mac OS X first launched they did so without an existing poll function. They later added poll() in Mac OS X 10.3, but we quickly discovered that it was broken (it returned a non-zero value when asked to wait for nothing) so in the <a href=\"https:\/\/curl.se\/\">curl project<\/a> we added a check in configure for that and subsequently avoided using poll() in all OS X versions to and including Mac OS 10.8 (Darwin 12). The code would instead switch to the alternative solution based on select() for these platforms.<\/p>\n\n\n\n<p>With the release of Mac OS X 10.9 &#8220;Mavericks&#8221; in October 2013, Apple had fixed their poll() implementation and we&#8217;ve built libcurl to use it since with no issues at all. The configure script picks the correct underlying function to use.<\/p>\n\n\n\n<p>Enter macOS 10.12 (yeah, its not called OS X anymore) &#8220;Sierra&#8221;, released in September 2016. Quickly <a href=\"https:\/\/github.com\/curl\/curl\/issues\/1057\">we discovered<\/a> that poll() once against did not act like it should and we are back to disabling the use of it in preference to the backup solution using select().<\/p>\n\n\n\n<p>The new error looks similar to the old problem: when there&#8217;s nothing to wait for and we ask poll() to wait N milliseconds, the 10.12 version of poll() returns immediately without waiting. Causing busy-loops. The problem has been reported to Apple and its Radar number is 28372390. (There has been no news from them on how they plan to act on this.)<\/p>\n\n\n\n<p><a href=\"http:\/\/pubs.opengroup.org\/onlinepubs\/7908799\/xsh\/poll.html\">poll() is defined by POSIX<\/a> and The Single Unix Specification it specifically says:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>If none of the defined events have occurred on any selected file descriptor, <i>poll()<\/i> waits at least <i>timeout<\/i> milliseconds for an event to occur on any of the selected file descriptors.<\/p>\n<\/blockquote>\n\n\n\n<p>We pushed a configure check for this in curl, to be part of the upcoming 7.51.0 release. I&#8217;ll also show you a small snippet you can use stand-alone below.<\/p>\n\n\n\n<p>Apple is hardly alone in the broken-poll department. Remember how Windows&#8217; <a href=\"https:\/\/daniel.haxx.se\/blog\/2012\/10\/10\/wsapoll-is-broken\/\">WSApoll is broken<\/a>?<\/p>\n\n\n\n<p>Here&#8217;s a little code snippet that can detect the 10.12 breakage:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;poll.h&gt;\n#include &lt;stdio.h&gt;\n#include &lt;sys\/time.h&gt;\n\nint main(void)\n{\n  struct timeval before, after;\n  int rc;\n  size_t us;\n\n  gettimeofday(&amp;before, NULL);\n  rc = poll(NULL, 0, 500);\n  gettimeofday(&amp;after, NULL);\n\n  us = (after.tv_sec - before.tv_sec) * 1000000 +\n    (after.tv_usec - before.tv_usec);\n\n  if(us &lt; 400000) {\n    puts(\"poll() is broken\");\n    return 1;\n  }\n  else {\n    puts(\"poll() works\");\n  }\n  return 0;\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Follow-up, January 2017<\/h2>\n\n\n\n<p>This poll bug has been <a href=\"https:\/\/github.com\/curl\/curl\/issues\/1057#issuecomment-271866997\">confirmed fixed<\/a> in the macOS 10.12.2 update (released on December 13, 2016), but I&#8217;ve found no official mention or statement about this fact.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When Mac OS X first launched they did so without an existing poll function. They later added poll() in Mac OS X 10.3, but we quickly discovered that it was broken (it returned a non-zero value when asked to wait for nothing) so in the curl project we added a check in configure for that &hellip; <a href=\"https:\/\/daniel.haxx.se\/blog\/2016\/10\/11\/poll-on-mac-10-12-is-broken\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">poll on mac 10.12 is broken<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,13],"tags":[273,33,404,219],"class_list":["post-9398","post","type-post","status-publish","format-standard","hentry","category-curl","category-net","tag-apple","tag-curl-and-libcurl","tag-mac-os-x","tag-network"],"_links":{"self":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/9398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/comments?post=9398"}],"version-history":[{"count":11,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/9398\/revisions"}],"predecessor-version":[{"id":25518,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/posts\/9398\/revisions\/25518"}],"wp:attachment":[{"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/media?parent=9398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/categories?post=9398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/daniel.haxx.se\/blog\/wp-json\/wp\/v2\/tags?post=9398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}