fix #811
Cherry pick c459263d27531b7856457b13e9b556b2aeb21dae