Properly deal with closed TLS streams

fixes #6892