-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathcircuit_state.go
32 lines (29 loc) · 1.13 KB
/
circuit_state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package healthsrv
import (
"fmt"
"github.com/deis/builder/pkg/sshd"
)
// circuitState determines whether circ.State() == sshd.ClosedState, and sends the results back on
// the various given channels. This func is intended to be run in a goroutine and communicates
// via the channels it's passed.
//
// If the circuit is closed, it passes an empty struct back on succCh. On failure, it sends an
// error back on errCh. At most one of {succCh, errCh} will be sent on. If stopCh is closed, no
// pending or future sends will occur.
func circuitState(circ *sshd.Circuit, succCh chan<- struct{}, errCh chan<- error, stopCh <-chan struct{}) {
// There's a race between the boolean eval and the HTTP error returned
// (the circuit could close between the two). This function should be polled to avoid that
// problem. If it's being used in a k8s probe, then you're fine because k8s will repeat the
// health probe and effectively re-evaluate the boolean.
if circ.State() != sshd.ClosedState {
select {
case errCh <- fmt.Errorf("SSH Server is not yet started"):
case <-stopCh:
}
return
}
select {
case succCh <- struct{}{}:
case <-stopCh:
}
}