Prevent crash on thread object cleanup.
Properly handle timeout on synchronous socket read.
Adds support for detecting local connection failures.