Apply patch from upstream #5385