Check if stream is closed before attempting reconnection

I believe the check to stop a stream connection if its closed should be earlier. I had a situation today where I have a stream listening in a goroutine and it is closed in another goroutine, but the first goroutine keeps listening.

This patch fixes my issue.