Ensure file is closed promptly in case of error
Fixes #35566
can you add a test Very difficult to add a test since the failure is during the constructor meaning that we have no references to the failed state.
I have pulled something together, but it requires a dependency on psutils and assumes that the test file is on a local disk.  Is that acceptable? A dependency on external libs for this is not great IMO. Are there tests for closed files for other file formats, e.g. excel or csv files? Could you try to emulate them? OK, let's follow up in the new PR #35587 (sorry, I deleted my repo in the meantime, so need a new PR).