close the web socket connection gracefully when possible