Thanks jukvalim for the report and initial patch, and Preston Timmons for review. Backport of c32bc1a7a7 from master