Fixing server closure race conditions