Fixed Unhandled Exception when socket closed