{"id":984,"date":"2009-06-04T12:07:32","date_gmt":"2009-06-04T16:07:32","guid":{"rendered":"http:\/\/www.scaredpoet.com\/wordpress\/?p=984"},"modified":"2009-06-22T14:46:30","modified_gmt":"2009-06-22T18:46:30","slug":"dealing-with-finicky-safari","status":"publish","type":"post","link":"https:\/\/scaredpoet.com\/blog\/?p=984","title":{"rendered":"Dealing with finicky Safari"},"content":{"rendered":"<p>So, let&#8217;s just say that you happen to be a Mac user, and browse the web on Safari, only to have this frustrating problem where some of your favorite websites are mysteriously starting to look like this when they load:<\/p>\n<p><img decoding=\"async\" src=\"\/images\/missingcss_scrn.png\" alt=\"Missing CSS\" \/><\/p>\n<p>What&#8217;s worse, once it happens to that one site, it starts happening on <strong>every site<\/strong> you navigate to.    The only way to stop this silly behavior is to quit Safari (sometimes a Force Quit is necessary), then relaunch and go back to what you&#8217;re doing&#8230; until it starts failing on you again.<\/p>\n<p>It seems like only certain specific, image-heavy sites cause Safari to act up, making you wonder if the problem is Safari, or a badly-coded website.  What&#8217;s worse, this problem (typically) doesn&#8217;t exist on FireFox or Opera.<\/p>\n<p>If you look in the browser&#8217;s Activity\/Debug window, you might see error messages popping up like crazy in red, that read something like:<\/p>\n<blockquote><p>POSIX error: Too many files open<\/p><\/blockquote>\n<p>Sound familiar?  This problem can be really annoying for some of us who  like Safari and some of its features, and would really rather not have to switch browsers.  <\/p>\n<p>But don&#8217;t fret.  There IS a solution.<!--more--><\/p>\n<p>The problem isn&#8217;t <strong>directly<\/strong> Safari, and while the the websites in question probably could use some better coding, the fault doesn&#8217;t exactly lie on that end, either.  As it turns out, OS X comes by default with a configuration that is rather restrictive and overprotective, and Safari sometimes gets a bit carried away in the number of resources it calls up at once.  And when they start fighting, you lose.<\/p>\n<p>For the tech-minded: the problem lies in a configuration file for <a href=\"http:\/\/developer.apple.com\/documentation\/Darwin\/Reference\/Manpages\/man8\/launchd.8.html#\/\/apple_ref\/doc\/man\/8\/launchd\">launchd<\/a> and <a href=\"http:\/\/developer.apple.com\/documentation\/Darwin\/Reference\/Manpages\/man1\/launchctl.1.html#\/\/apple_ref\/doc\/man\/1\/launchctl\">launchctl<\/a>, the two main gatekeepers for apps launched on a Mac.  A config file specifies how many files and processes are allowed to be open at once.  And on most macs, the settings are set way low.<\/p>\n<p>Before we proceed, It should be pointed out: if you&#8217;re not having any issues at all with Safari, then you probably shouldn&#8217;t be messing with any settings, because they&#8217;re likely working just fine for you. If however, you&#8217;re frustrated with seeing broken pages and apparent crashes by the web browser, then the following steps may assist you.<\/p>\n<p>To begin: You will need to <a href=\"http:\/\/www-jerry.oit.duke.edu\/mac\/osx_shell_terminal_window.html\">open up a Terminal Window<\/a> on your mac, and enter the following command:<\/p>\n<p><code>sudo launchctl limit<\/code><\/p>\n<p>The output will look something like this (possibly with slightly different values):<br \/>\n<img decoding=\"async\" src=\"\/images\/launchctl.png\" alt=\"launchctl output\" \/><\/p>\n<p>The values of interest here are &#8220;maxproc&#8221; and &#8220;maxfiles.&#8221;  These are soft and hard limits for how may processes the OS will allow applications to spawn at once, and the maximum number of files that OS X will allow to be open.  In my case, I have &#8220;soft limits&#8221; of 266 max processes, and 256 maximum open files.  For most everyday uses this appears to be enough, but is a little too conservative when you&#8217;r loading up graphic intensive websites or applications.  Safari appears to be kept on a very short leash, and chokes when it hits these &#8220;soft&#8221; limits.<\/p>\n<p>If you find yourself in the same boat, there is a way to bump up these limits.  We don&#8217;t want to get too liberal with these limits, as they do serve an important function in making sure that a runaway application doesn&#8217;t take the whole system down.  But, most modern macs, with multiple CPUs and oodles of RAM, can definitely juggle more than the limits shown here.<\/p>\n<p>Changing the values involves issuing a couple of commands into the terminal.  First, make sure you have the <strong>old<\/strong> values written down.  You might even want to <a href=\"http:\/\/guides.macrumors.com\/Taking_Screenshots_in_Mac_OS_X\">take a screenshot<\/a> of the original values, as I did above.  This assures that you can go back to these values if the changes cause other, more undesirable problems.<\/p>\n<p>Now, we&#8217;re ready to modify things a bit.  Let&#8217;s start with max processes, issuing this command into the terminal:<\/p>\n<p><code>echo \"limit maxproc 1000 2000\" | sudo tee -a \/etc\/launchd.conf<\/code><\/p>\n<p>Note: you will be asked for a password, as an &#8220;administrator&#8221; user must make this change.<\/p>\n<p>This modifies (or creates, if it doesn&#8217;t exist) a configuration file to let OS X know that we want higher limits (in this case, 1000 soft, 2000 hard limit) to this parameter.<\/p>\n<p>Next is maxfiles:<\/p>\n<p><code>echo \"limit maxfiles 4096 unlimited\" | sudo tee -a \/etc\/launchd.conf<\/code><\/p>\n<p>Once these changes are done, the mac must be rebooted for them to take effect.<\/p>\n<p>This seems to have resolved the problem for me, and hopefully will solve the issue for the <a href=\"http:\/\/www.google.com\/search?client=safari&#038;rls=en-us&#038;q=%22too+many+files+open%22+safari&#038;ie=UTF-8&#038;oe=UTF-8\">many others<\/a> who have complained of similar problems, and not yet found a solution.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, let&#8217;s just say that you happen to be a Mac user, and browse the web on Safari, only to have this frustrating problem where some of your favorite websites are mysteriously starting to look like this when they load: What&#8217;s worse, once it happens to that one site, it starts happening on every site [&hellip;]<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[96,125,127,126,128,130,131,129],"class_list":["post-984","post","type-post","status-publish","format-standard","hentry","category-gadgets-widgits-and-whatzits","tag-mac","tag-os-x","tag-posix","tag-safari","tag-error","tag-launchctl","tag-launchd","tag-too-many-files-open"],"_links":{"self":[{"href":"https:\/\/scaredpoet.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scaredpoet.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scaredpoet.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scaredpoet.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/scaredpoet.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=984"}],"version-history":[{"count":0,"href":"https:\/\/scaredpoet.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/984\/revisions"}],"wp:attachment":[{"href":"https:\/\/scaredpoet.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scaredpoet.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scaredpoet.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}