bugfix: close forgotten file descriptors

I did not succeed in writing tests to detect the error, but the current changes have corrected errors occurring in our application that requires alembic.