fixed bug trying to write when websocket is closing