Fixed #22882 -- Fixed a UnicodeDecodeError in flush.

Thanks djbaldey for the report.