Skip to content

Instantly share code, notes, and snippets.

@nathanhleung
Last active February 24, 2024 08:25
Show Gist options
  • Star 29 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanhleung/2ceeda4c743f2a1cf3d670c8b90445f6 to your computer and use it in GitHub Desktop.
Save nathanhleung/2ceeda4c743f2a1cf3d670c8b90445f6 to your computer and use it in GitHub Desktop.
Fix macOS Hanging Issue

Fix macOS Hanging Issue

Problem

Hey Apple users:

If you're now experiencing hangs launching apps on the Mac, I figured out the problem using Little Snitch.

It's trustd connecting to http://ocsp.apple.com

Denying that connection fixes it, because OCSP is a soft failure.

(Disconnect internet also fixes.)

@lapcatsoftware (Tweet)

Solutions

Both of these solutions do the same thing and prevent connections to ocsp.apple.com so your computer doesn't hang anymore. Pick the one that you feel more comfortable with.

Solution 1

The solution involves visually editing your /etc/hosts file with the vi command-line editor. Original source is this tweet, with corrections from replies:

  1. Disconnect Internet (if possible)
  2. Open Terminal
  3. Run sudo vi /etc/hosts
  4. Type G$ (go to end of file)
  5. Type i, right arrow, enter
  6. Type 0.0.0.0 ocsp.apple.com
  7. Press esc then type :x then press enter to save and quit
  8. Reconnect Internet (if you disconnected it)
  9. sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder to flush DNS

Solution 2

This solution has the same effect as the above solution (appending a line to /etc/hosts) and involves only one command. If you're not familiar with the Terminal or vi, you should do this.

  1. Open Terminal
  2. Run echo "127.0.0.1 ocsp.apple.com" | sudo tee -a /etc/hosts to append 127.0.0.1 ocsp.apple.com to the end of /etc/hosts
  3. sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder to flush DNS

Thanks @gnb for this one-liner!

Example /etc/hosts

After you're done, your /etc/hosts file should look something like:

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1	localhost
255.255.255.255	broadcasthost
::1             localhost

# (You might not have everything that's above this line, but your file should end with the line below)
127.0.0.1 ocsp.apple.com

You can type cat /etc/hosts in your Terminal to print the contents of the /etc/hosts file to your screen, if you want to verify.

AFTER Apple Fixes Their Issue

Once Apple fixes this issue upstream, you should get rid of the changes that were made to the /etc/hosts file in the above procedure.

  1. Open Terminal
  2. Run sudo vi /etc/hosts
  3. Type G$ (go to end of file)
  4. Make sure you're on the line that reads 127.0.0.1 ocsp.apple.com (i.e. the line you added). If you aren't, use your up and down arrow keys so your cursor is on that line.
  5. Type dd to delete the line.
  6. Press esc then type :x then press enter to save and quit

Further Reading

If you're curious what the Online Certificate Status Protocol (OCSP) is/the impacts of this change, check out the links below.

You should probably follow the instructions above to get rid of the changes that were made as soon as Apple fixes the issue.

Acknowledgments

  1. Send traffic to 0.0.0.0 instead of 127.0.0.1 from @michaelmior (Source)
  2. Typo in ocsp, original tweet read "oscp" from @ofergayer (Source)
  3. Restarting may not be necessary from @danbenjamin (Source)
  4. Right arrow, not left arrow from @simon (Source)
  5. Alternate one-line solution from @gnb (Source)
@parstra
Copy link

parstra commented Nov 13, 2020

I like the one-liner for adding the entry to /etc/hosts file, I think it would be helpful for people to create a backup file with the original version and then restore it instead of entering vi (few people can get out successfully :-p )

You can wrap solution 2 with

sudo cp /etc/hosts{,_old}

in the beginning to create the backup, and

sudo cp /etc/hosts{_old,}

at the end, to restore it.

@slayerwolf00fa
Copy link

nice job

@NightMachinery
Copy link

Does this work as of 2024 on macOS Sonoma?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment