This relands commit e0963ae2, which was reverted on commit 82c4153e due to a test failure, which turned out to be a false positive.