in pkg/client/client_v2.go [459:502]
func (c *clientV2) checkinRoundTrip() {
checkinCtx, checkinCancel := context.WithCancel(c.ctx)
defer checkinCancel()
// Return immediately if we can't establish an initial RPC connection.
checkinClient, err := c.client.CheckinV2(checkinCtx)
if err != nil {
c.errCh <- err
return
}
// wg tracks when the reader and writer loops terminate.
var wg sync.WaitGroup
// readerDone is closed by the reader (expected state) loop when it
// terminates, so the writer (observed state) loop knows to return
// as well.
readerDone := make(chan struct{})
// expected state check-ins (reader)
wg.Add(1)
go func() {
defer wg.Done()
defer close(readerDone)
expected, err := chunk.RecvExpected(checkinClient)
for ; err == nil; expected, err = chunk.RecvExpected(checkinClient) {
c.applyExpected(expected)
}
if !errors.Is(err, io.EOF) {
c.errCh <- err
}
}()
// observed state check-ins (writer)
wg.Add(1)
go func() {
defer wg.Done()
c.checkinWriter(checkinClient, readerDone)
_ = checkinClient.CloseSend()
}()
// Wait for reader and writer to finish before returning.
wg.Wait()
}