code: func (a *Agent) reapServicesInternal() {
  	reaped := make(map[string]bool)
  	for checkID, cs := range a.State.CriticalCheckStates() {
  		serviceID := cs.Check.ServiceID
  
  		// There's nothing to do if there's no service.
  		if serviceID == "" {
  			continue
  		}
  
  		// There might be multiple checks for one service, so
  		// we don't need to reap multiple times.
  		if reaped[serviceID] {
  			continue
  		}
  
  		// See if there's a timeout.
  		// todo(fs): this looks fishy... why is there another data structure in the agent with its own lock?
  		a.stateLock.Lock()
  		timeout := a.checkReapAfter[checkID]
  		a.stateLock.Unlock()
  
  		// Reap, if necessary. We keep track of which service
  		// this is so that we won't try to remove it again.
  		if timeout > 0 && cs.CriticalFor() > timeout {
  			reaped[serviceID] = true
  			if err := a.RemoveService(serviceID, true); err != nil {
  				a.logger.Printf("[ERR] agent: unable to deregister service %q after check %q has been critical for too long: %s",
  					serviceID, checkID, err)
  			} else {
  				a.logger.Printf("[INFO] agent: Check %q for service %q has been critical for too long; deregistered service",
  					checkID, serviceID)
  			}
  		}
  	}
  }
docs: // reapServicesInternal does a single pass, looking for services to reap.