Fix crash caused by bad return values from stream methods

Must return -1 on error.
Fix crash on teardown by waiting for `_do_close()` to finish