This is a cherry-pick of e4dca4f. This was originally committed on 5.1. This is a forward port.
e4dca4f