// check attempts to beat a Heart several times within a timeout, returning the
// log index at which the beat succeeded or an error
176730
func check(hrt heart.Heart, ttl time.Duration) (idx uint64, err error) {
	// time out after a third of the machine presence TTL, attempting
	// the heartbeat up to four times
	timeout := ttl / 3
	interval := timeout / 4

	tchan := time.After(timeout)
	next := time.After(0)
	for idx == 0 {
		select {
		case <-tchan:
			err = errors.New("Monitor timed out before successful heartbeat")
			return
		case <-next:
			idx, err = hrt.Beat(ttl)
			if err != nil {
				log.Debugf("Monitor heartbeat function returned err, retrying in %v: %v", interval, err)
			}

			next = time.After(interval)
		}
	}

	return
}
531188
func (c *FakeCSRF) Check(req *http.Request, value string) bool {
	return c.Token == value
}
1216920
func (u *updater) Check() error {
	u.mu.Lock()
	defer u.mu.Unlock()

	return u.status
}
198348
func (c *inflationOptions) Check() error {
	_, err := strkey.Decode(strkey.VersionByteAccountID, c.AccountID)
	if err != nil {
		return ErrInvalidAccountID
	}
	if c.Destination == "" {
		return ErrDestinationMissing
	}

	return nil
}
9608
func (f *JSONConfigFile) Check() error {
	return PickFirstError(
		// Feel free to add others here..
		func() error {
			_, err := f.GetRunMode()
			return err
		}(),
	)
}
363773
func (hc *TCPChecker) Check(timeout time.Duration) *Result {
	msg := fmt.Sprintf("TCP connect to %s", hc.addr())
	start := time.Now()
	if timeout == time.Duration(0) {
		timeout = defaultTCPTimeout
	}
	deadline := start.Add(timeout)

	tcpConn, err := dialTCP(hc.network(), hc.addr(), timeout, hc.Mark)
	if err != nil {
		msg = fmt.Sprintf("%s; failed to connect", msg)
		return complete(start, msg, false, err)
	}
	conn := net.Conn(tcpConn)
	defer conn.Close()

	// Negotiate TLS if this is required.
	if hc.Secure {
		// TODO(jsing): We probably should allow the server name to
		// be specified via configuration...
		host, _, err := net.SplitHostPort(hc.addr())
		if err != nil {
			msg = msg + "; failed to split host"
			return complete(start, msg, false, err)
		}
		tlsConfig := &tls.Config{
			InsecureSkipVerify: !hc.TLSVerify,
			ServerName:         host,
		}
		tlsConn := tls.Client(conn, tlsConfig)
		if err := tlsConn.Handshake(); err != nil {
			return complete(start, msg, false, err)
		}
		conn = tlsConn
	}

	if hc.Send == "" && hc.Receive == "" {
		return complete(start, msg, true, err)
	}

	err = conn.SetDeadline(deadline)
	if err != nil {
		msg = fmt.Sprintf("%s; failed to set deadline", msg)
		return complete(start, msg, false, err)
	}

	if hc.Send != "" {
		err = writeFull(conn, []byte(hc.Send))
		if err != nil {
			msg = fmt.Sprintf("%s; failed to send request", msg)
			return complete(start, msg, false, err)
		}
	}

	if hc.Receive != "" {
		buf := make([]byte, len(hc.Receive))
		n, err := io.ReadFull(conn, buf)
		if err != nil {
			msg = fmt.Sprintf("%s; failed to read response", msg)
			return complete(start, msg, false, err)
		}
		got := string(buf[0:n])
		if got != hc.Receive {
			msg = fmt.Sprintf("%s; unexpected response - %q", msg, got)
			return complete(start, msg, false, err)
		}
	}
	return complete(start, msg, true, err)
}
1019811
func Check() []Result {
	results := make([]Result, 0, len(checkers))
	for _, checker := range checkers {
		startTime := time.Now()
		if raw, err := checker.check(); err != nil && err != ErrDisabledComponent {
			results = append(results, Result{
				Name:     checker.name,
				Raw:      raw,
				Status:   "fail - " + err.Error(),
				Duration: time.Now().Sub(startTime),
			})
		} else if err == nil {
			results = append(results, Result{
				Name:     checker.name,
				Raw:      raw,
				Status:   HealthCheckOK,
				Duration: time.Now().Sub(startTime),
			})
		}
	}
	return results
}
1352757
func (c *CheckTCP) check() {
	conn, err := c.dialer.Dial(`tcp`, c.TCP)
	if err != nil {
		c.Logger.Printf("[WARN] agent: Check %q socket connection failed: %s", c.CheckID, err)
		c.Notify.UpdateCheck(c.CheckID, api.HealthCritical, err.Error())
		return
	}
	conn.Close()
	c.Logger.Printf("[DEBUG] agent: Check %q is passing", c.CheckID)
	c.Notify.UpdateCheck(c.CheckID, api.HealthPassing, fmt.Sprintf("TCP connect %s: Success", c.TCP))
}
1180464
func (c *healthCheck) Check() (warnings, errors []error) {
	if err := c.f(c.client); err != nil {
		return nil, []error{err}
	}
	return nil, nil
}
1079046
func (fn FilterFunc) Check(rls *rspb.Release) bool {
	if rls == nil {
		return false
	}
	return fn(rls)
}
1174292
func (ts *Store) Check(id string) (string, error) {
	treeStoreKeyLock, err := lock.SharedKeyLock(ts.lockDir, id)
	if err != nil {
		return "", errwrap.Wrap(errors.New("error locking tree store"), err)
	}
	defer treeStoreKeyLock.Close()

	return ts.check(id)
}
234655
func Check(conn *grpc.ClientConn) (bool, error) {
	res, err := healthpb.NewHealthClient(conn).Check(context.Background(), &healthpb.HealthCheckRequest{})
	if err != nil {
		return false, err
	}
	return res.Status == healthpb.HealthCheckResponse_SERVING, nil
}
665213
func (r *RegisterMonitor) heartbeat() {
	// Trigger the health check passing. We don't need to retry this
	// since we do a couple tries within the TTL period.
	if err := r.Client.Agent().PassTTL(r.checkID(), ""); err != nil {
		if !strings.Contains(err.Error(), "does not have associated") {
			r.Logger.Printf("[WARN] proxy: heartbeat failed: %s", err)
		}
	}
}
259998
func (s *Server) Check(ctx context.Context, in *api.HealthCheckRequest) (*api.HealthCheckResponse, error) {
	s.mu.Lock()
	defer s.mu.Unlock()
	if in.Service == "" {
		// check the server overall health status.
		return &api.HealthCheckResponse{
			Status: api.HealthCheckResponse_SERVING,
		}, nil
	}
	if status, ok := s.statusMap[in.Service]; ok {
		return &api.HealthCheckResponse{
			Status: status,
		}, nil
	}
	return nil, status.Errorf(codes.NotFound, "unknown service")
}
1139297
func (ts *timerSet) check(now time.Time) error {
	for i, t := range ts.ts {
		if now.After(t.deadline) {
			ts.ts = append(ts.ts[:i], ts.ts[:i+1]...)
			if t.cb != nil {
				logf(logTypeHandshake, "Timer %s expired [%v > %v]", t.label, now, t.deadline)
				cb := t.cb
				t.cb = nil
				err := cb()
				if err != nil {
					return err
				}
			}
		} else {
			break
		}
	}
	return nil
}
918979
func (g *GopathTest) Check(err error) {
	if err == nil {
		return
	}
	g.Fatal(err)
}
1022140
func (l *HealthzAdaptor) Check(req *http.Request) error {
	l.pointerLock.Lock()
	defer l.pointerLock.Unlock()
	if l.le == nil {
		return nil
	}
	return l.le.Check(l.timeout)
}