infinite loop if the connection was lost unexpectedly. Also fixed release of connection on exit. Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>