Backport of 9c19aff7c7 from main.
9c19aff7c7
Thanks Carl Meyer for the report and Tim Graham for the review.