backport #21615 and #21323