Fix crash when server socket is closed.