fixing race condition where service unregisters after it's removed