Fix bugs related to reconnection and TCP errors

TCP errors were not handled, and reconnection failed for many reasons.
New test with a proxy server to assert driver's behavior to TCP closes.