From 5b9f7013177ca48ddf1342beac3e6acb68756ae8 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Mon, 22 Nov 2021 20:16:38 +0100 Subject: [PATCH] fix(measurex): handle case where TH is nil (#610) This case happens when the TH fails. See https://github.com/ooni/probe/issues/1895. --- internal/measurex/archival.go | 11 +++++++---- internal/measurex/measurement.go | 3 ++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/measurex/archival.go b/internal/measurex/archival.go index 2feb65f..055d250 100644 --- a/internal/measurex/archival.go +++ b/internal/measurex/archival.go @@ -496,11 +496,14 @@ type ArchivalTHMeasurement struct { } // NewArchivalTHMeasurement creates the archival representation of THMeasurement. -func NewArchivalTHMeasurement(in *THMeasurement) *ArchivalTHMeasurement { - return &ArchivalTHMeasurement{ - DNS: NewArchivalDNSMeasurementList(in.DNS), - Endpoints: NewArchivalHTTPEndpointMeasurementList(in.Endpoints), +func NewArchivalTHMeasurement(in *THMeasurement) (out *ArchivalTHMeasurement) { + if in != nil { + out = &ArchivalTHMeasurement{ + DNS: NewArchivalDNSMeasurementList(in.DNS), + Endpoints: NewArchivalHTTPEndpointMeasurementList(in.Endpoints), + } } + return } // diff --git a/internal/measurex/measurement.go b/internal/measurex/measurement.go index 1d04652..0cac00a 100644 --- a/internal/measurex/measurement.go +++ b/internal/measurex/measurement.go @@ -31,7 +31,8 @@ type URLMeasurement struct { // if we choose to follow redirections. RedirectURLs []string - // TH is the measurement collected by the TH. + // TH is the measurement collected by the TH. This field + // will be nil if we cannot contact the TH. TH *THMeasurement // TotalRuntime is the total time to measure this URL.