If I'm not mistaken this will cause the client connection to be closed, but I guess a client will try to reconnect immediately, which would result in a reconnection loop (as long as the server thread is running).

Maybe 'sleep' for some time first (and hope the server process ends before the nap is over)?