tls: handle the case if endpoint has disconnected
Merge pull request #1625 from bmiklautz/disconnect

tls: handle the case if endpoint has disconnected