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)
@JeffreyCA
Copy link

There are still several of typos of oscp instead of ocsp in this file.

@lukehinds
Copy link

You don't need to disconnect from the internet

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder will refresh your hosts.

@tralik
Copy link

tralik commented Nov 13, 2020

Type G$ (go to end of file)
Type i, right arrow, enter

can be replace with: Type Go

G: go to end of file
o: begin a new line below the cursor and insert text

@angrox
Copy link

angrox commented Nov 13, 2020

Solution2 has a wrong syntax for /etc/hosts - the hostname is needed, not the url.

@Emzy
Copy link

Emzy commented Nov 13, 2020

echo "127.0.0.1 http://oscp.apple.com" | sudo tee -a /etc/hosts
is not right. This is:
echo "127.0.0.1 oscp.apple.com" | sudo tee -a /etc/hosts

@martinstoyanov
Copy link

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

Why should we do this?

@dan
Copy link

dan commented Nov 13, 2020

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

Why should we do this?

In theory, you want apple to certify third-party apps when launching them. If you don't care, keep your /etc/hosts changes.

@lysol
Copy link

lysol commented Nov 13, 2020

I know you wanted to be the smartest guy in the room, but URLs don't go into /etc/hosts

@nathanhleung
Copy link
Author

There are still several of typos of oscp instead of ocsp in this file.

Thanks, fixed this

@nathanhleung
Copy link
Author

I know you wanted to be the smartest guy in the room, but URLs don't go into /etc/hosts

Thanks, when copying from Twitter http:// was accidentally appended to the beginning of the hostname. Fixed this

@nathanhleung
Copy link
Author

echo "127.0.0.1 http://oscp.apple.com" | sudo tee -a /etc/hosts
is not right. This is:
echo "127.0.0.1 oscp.apple.com" | sudo tee -a /etc/hosts

Thanks, the http:// was inadvertently appended to the beginning of the hostname when copying from Twitter. Fixed this

@nathanhleung
Copy link
Author

You don't need to disconnect from the internet

sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder will refresh your hosts.

Thanks, removed the instruction to restart and replaced it with that command

@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