diff --git a/internal/cmd/oohelperd/measure.go b/internal/cmd/oohelperd/measure.go index 5035642..887d2a0 100644 --- a/internal/cmd/oohelperd/measure.go +++ b/internal/cmd/oohelperd/measure.go @@ -43,6 +43,22 @@ func measure(ctx context.Context, config *handler, creq *ctrlRequest) (*ctrlResp }) } + // wait for DNS measurements to complete + wg.Wait() + + // start assembling the response + cresp := new(ctrlResponse) + select { + case cresp.DNS = <-dnsch: + default: + // we need to emit a non-nil Addrs to match exactly + // the behavior of the legacy TH + cresp.DNS = ctrlDNSResult{ + Failure: nil, + Addrs: []string{}, + } + } + // tcpconnect: start tcpconnch := make(chan tcpResultPair, len(creq.TCPConnect)) for _, endpoint := range creq.TCPConnect { @@ -67,26 +83,20 @@ func measure(ctx context.Context, config *handler, creq *ctrlRequest) (*ctrlResp Wg: wg, }) - // wait for measurement steps to complete + // wait for endpoint measurements to complete wg.Wait() - // assemble response - cresp := new(ctrlResponse) - select { - case cresp.DNS = <-dnsch: - default: - // we need to emit a non-nil Addrs to match exactly - // the behavior of the legacy TH - cresp.DNS = ctrlDNSResult{ - Failure: nil, - Addrs: []string{}, - } - } + // continue assembling the response cresp.HTTPRequest = <-httpch cresp.TCPConnect = make(map[string]ctrlTCPResult) - for len(cresp.TCPConnect) < len(creq.TCPConnect) { - tcpconn := <-tcpconnch - cresp.TCPConnect[tcpconn.Endpoint] = tcpconn.Result +Loop: + for { + select { + case tcpconn := <-tcpconnch: + cresp.TCPConnect[tcpconn.Endpoint] = tcpconn.Result + default: + break Loop + } } return cresp, nil