Cherry-pick up to 670abe568d2ac87be1ebb00379a13d06a1f61ca7.