Should close #6377 and #15239 (cherry picked from commit e430f3f61ae45ca0e8e251f96a1605bdb9299eb1)
f580cddc09