From 50054f565972e51ecd4ec72f9a24fc80175317d8 Mon Sep 17 00:00:00 2001 From: Simone Basso Date: Thu, 16 Mar 2023 17:24:08 +0100 Subject: [PATCH] [backport] fix(webconnectivitylte): avoid data race This diff backports 297360dfa007583c3fcd75bc83e516b82d93f8be. Closes https://github.com/ooni/probe/issues/2434 --- internal/experiment/webconnectivitylte/iox.go | 4 +++- internal/experiment/webconnectivitylte/measurer.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/experiment/webconnectivitylte/iox.go b/internal/experiment/webconnectivitylte/iox.go index 5063e0db73..4ae851c4a2 100644 --- a/internal/experiment/webconnectivitylte/iox.go +++ b/internal/experiment/webconnectivitylte/iox.go @@ -33,8 +33,10 @@ func StreamAllContext(ctx context.Context, reader io.Reader) ([]byte, error) { defer cancel() go func() { - buffer := make([]byte, 1<<13) for { + // Implementation note: the buffer MUST be created at each + // loop, otherwise we're data-racing with the reader. + buffer := make([]byte, 1<<13) count, err := reader.Read(buffer) if count > 0 { data := buffer[:count] diff --git a/internal/experiment/webconnectivitylte/measurer.go b/internal/experiment/webconnectivitylte/measurer.go index 9926150c18..2eeef646d0 100644 --- a/internal/experiment/webconnectivitylte/measurer.go +++ b/internal/experiment/webconnectivitylte/measurer.go @@ -37,7 +37,7 @@ func (m *Measurer) ExperimentName() string { // ExperimentVersion implements model.ExperimentMeasurer. func (m *Measurer) ExperimentVersion() string { - return "0.5.22" + return "0.5.23" } // Run implements model.ExperimentMeasurer.