backport 8f1a5471ce9de2c8276540a8e683c8f891f6b399 from master