Patch in upstream changes from https://gerrit.wikimedia.org/r/#/c/100834/