Make sure socket gets closed regardless of errors in the main try/catch block