Fix error on closed socket