call close on the underlying stream even if flush raises (closes #16597)

Patch by Serhiy Storchaka.
5 files changed